Traditional Culture Encyclopedia - Traditional festivals - Svg online drawing code-I want to be a vector editor (drawing tool), how to save the edited shape as a file in svg format.
Svg online drawing code-I want to be a vector editor (drawing tool), how to save the edited shape as a file in svg format.
Also known as bitmap and pixel map, the image is composed of pixels, and the number of pixels will determine the display quality and file size of the image. The higher the resolution of the image, the clearer the display and the larger the space occupied by the file. When the image is enlarged, it will be distorted. It can be seen that the whole image is composed of many pixels.
vector graphics
Using XML to describe two-dimensional graphics and drawing programs, the graphics quality will not be lost when the vector image is enlarged or changed in size.
& lt Canvas & gt and
Save (short for saving)
canvas
Graphs and charts
Both svg and Canvas can represent charts (such as histogram, scatter chart, pie chart, etc. ). In the common graphic chart library, Baidu's echarts is based on Canvas, and D3 is based on svg.
The xmlns attribute defines the SVG namespace (if SVG is embedded in an HTML page and provided as that page, the xmlns attribute is not required).
use
Path element is one of the most powerful basic shapes of SVG. It can not only create other basic shapes, but also create more other shapes. You can draw rectangles (right-angled rectangles or rounded rectangles), circles, ellipses, polylines, polygons and some other shapes, such as Bezier curves and conic curves.
The shape of the path element is defined by the attribute D, and the value of the attribute D is a sequence of "command+parameter".
The following commands are available for path data: (see command details)
The four parameters of viewBox represent: the minimum x-axis value; Minimum y-axis value; Width; Height.
For svg global scaling
A dashed line representing the drawn edge. Optional values are: None,
Represents the starting offset of the dotted line. Optional values include:
If the value of stroke-dasharray is very large, exceeding the total length of stroke path, and css animation is added to change the value of stroke-dashoffset, the stroke display will be displayed from the beginning for a period of time.
Android picture series (2)- static SVG picture SVG picture is a picture format that can support arbitrary scaling. It is defined by xml and drawn by path path in canvas, which is quite different from the traditional bitmap.
SVG has been popular in the front end for a long time. In Android, Google didn't support it until 5.0. After 14 came out, compatibility was a big problem. With the release of version 23.2.0 of 20 16.2V7 package, there is a relatively perfect compatibility scheme.
I won't write the concept of SVG, just consider it a doctrine.
No, let's take a look at what SVG vector graphics in android are.
Look, this is an SVG vector picture, an xml file and a preview on the right. Let's talk about the advantages of this thing first: the scaling is not distorted and the volume is small. This SVG picture is only 970 bytes ... powerful, infinitely better than a picture in png format. We have to adapt to png, make multiple sets, and then change the name one by one and copy it into the project. With SVG, mom doesn't have to worry about our homework anymore. ...
There are several labels to explain here:
The following is a detailed attribute description:
Ok, let's start introducing SVG.
First of all, we need to explain two concepts-SVG and Vector.
SVG, namely ScalableVectorGraphics, has been widely used in the front end.
Vector, in Android, refers to VectorDrawable, which is the vector diagram in Android.
Therefore, it can be said that Vector is an SVG implementation in Android, because Vector in Android does not support all SVG grammars, and it is unnecessary, because the complete SVG grammar is very complicated, but the supported SVG grammar is enough, especially the Path grammar, which is almost the standard of Vector in Android.
Android is compatible with SVG in a simplified way. By using its Path tag, almost all other tags in SVG can be implemented. Although it may be a bit complicated, you can do all these things and tools, so don't worry about complicated writing.
The path instruction is parsed as follows:
Description of support:
M=moveto(MX, y): Move the brush to the specified coordinate position.
L=lineto(LX, y): Draw a straight line to the specified coordinate position.
H=horizontallineto(HX): Draw a horizontal line at the specified X coordinate position.
V=verticallineto(VY): Draw a vertical line at the specified Y coordinate position.
C = Curveto (cx 1, y 1, x2, y2, endx, endy): cubic Bezier curve.
S=smoothcurveto(SX2,Y2,ENDX,ENDY)
Q = quadratic Bezier curve (qx, y, endx, endy): quadratic Bezier curve.
T = Smooth Quadratic Belzier Courveto (Tendx, Endy): Mapping
A = elliptic arc (ARX, ry, x rotation, flag 1, flag2, x, y): arc.
Z=closepath (): Close the path.
The coordinate axis is centered on (0,0), the X axis is horizontally to the right, and the Y axis is horizontally downward.
All instructions are case-sensitive. Absolute positioning in uppercase, referring to the global coordinate system; Lowercase relative positioning, refer to the parent container coordinate system.
Spaces between instructions and data can be omitted.
When the same instruction appears multiple times, only one instruction can be used.
Note that when dealing with' m', it just moved the brush and didn't draw anything. It can also draw discontinuous lines at the same time on the basis given later.
With regard to these grammars, what developers need is not to be completely proficient, but to be able to understand, and everything else can be realized by tools.
Here is an article about the drawing of Androidvector tag PathData, which describes the drawing of path in SVG in detail.
Well, these are all conceptual things. Let's have a look.
The use of SVG can be divided into two types. One is static SVG vector diagram, which is the protagonist of this paper and the main content of this chapter. The other is SVG vector animation, which is an advanced application of SVG. Adding objectAnimator animation to static SVG is widely used and is the core practice to realize dynamic interaction of androidicon.
Everyone has seen the SVG diagram above. We just write an xml file and use tags to describe how to draw the patterns we want, such as canvas size, color, path and so on. , and then to the system for drawing.
Now let's take a look at how SVG is applied in andorid and how it is compatible with versions below 5.0.
Although SVG has been used in the front end for a long time, it has been supported on android since 5.0. The system above 5.0 is very simple to use, just like using PNG pictures before.
First of all, the bearing mode of SVG images in android is an xml file, so the SVG images given to us by UI cannot be used directly. Here google provides us with the loading mode.
Androidstudio can directly use svg in version 2.3.3, and create a new SVGDemo project and a new VectorAsset file: app->; main->; New-> VectorAsset as shown in the figure:
We choose LocalFile to import the local svg file, name the file and click Next->; Finish adding one. Can draw xml files in the directory.
Well, such svg images have been added to our project and can be used directly. Of course, before that, we put SVG pictures in that drawable folder. It is necessary to say this question:
One thing needs to be explained. We can put the svg vector graph file in the drawable root directory. Android system will not scale the resolution of svg vector pictures according to your storage in different drawable folders, so we don't have to prepare multiple sets of pictures like when using PNG pictures. The default storage address of imported SVG pictures is the drawable root directory, so we can put it here. Of course, we can also write our own SVG pictures, all of which are xml. We can view the preview after writing the path ourselves, and generally don't write it ourselves. This is all the work of the UI.
It doesn't matter. Systems above 5.0 can use SVG like ordinary png pictures. You can try.
Compatibility of SVG version 4.x According to the change of SVG application scope, the configuration is gradually increased.
At this point, imageview will not work. We need to use AppCompatActivity or AppCompatImageView, and then we need to import the V7 package.
Gradle requires the following configuration:
The system will automatically generate corresponding drawable graphics for SVG in version 4. X. At this time, SVG does not have the feature of infinite stretching, and the purpose of gradle configuration is to get rid of this.
For example:
Resource settings cannot use src, but srcCompat must be used. At this point, we can see graphics instead of SVG features.
At this time, the above settings are not enough. We add the following settings to the activity or global where the view is located.
Then that's not enough. We must add a container for SVG images, such as selector, in order to use it normally, such as setting images for textview and setting images through custom properties.
This vc_halfstart_24dp is an SVG picture.
We have to add the official vectorDrawable support library, which supports at least 23.2.0.
This is basically no problem.
If SVG cooperates with custom views, we need to read SVG and then convert it into a path to draw. SVG is also an xml file in essence, so it also adopts the idea of parsing xml files, and of course there are other ideas of converting SVG into path.
SVG foreplay-it provides some ideas to enrich your vision, so take a look.
I want to be a vector graph editor (drawing tool) and how to save the edited graph as an svg file. Import pictures in SVG format into the above web pages, convert them into JPEG format online, and then download and save them.
Or:
Download SVG viewing tool AdobeSVGViewer3.03.
- Previous article:What are the four major travel notes in junior high school?
- Next article:What kind of clothes did Qiang men and women wear in the past?
- Related articles
- Inner Mongolia feature clothes
- Vegetarian Culture of Wang Manor
- What is the edition of Guangxi primary school textbooks in 2022?
- The first class sports lesson plan: one-legged jumping obstacles
- What magical food is the bloody hairy belly of Chongqing Huangmaodu Hot Pot?
- What does it cost to build a website for a company?
- What jobs are likely to be replaced by robots in the future?
- Which Taobao clothing stores do you like to visit?
- What line combination does the traditional fishing pole use?
- What are the English songs in qq dazzle dance?