iOS used in SVG format images

SVG is an XML-based syntax of image formats, it stands for scalable vector graphics (Scalable Vector Graphics). Other image formats are based on pixel processing, SVG is part of the shape description of the image, so it is essentially a text file, a small volume, and no matter how many times will not be amplified distortion.

WebView can be used in iOS to load and display pictures SVG format. code show as below:

NSString *svgName = @"fileName.svg";
NSString *svgPath = [[NSBundle mainBundle] pathForResource:svgName ofType:nil];
NSData *svgData = [NSData dataWithContentsOfFile:svgPath];
NSString *reasourcePath = [[NSBundle mainBundle] resourcePath];
NSURL *baseUrl = [[NSURL alloc] initFileURLWithPath:reasourcePath isDirectory:true];
UIWebView *webView = [[UIWebView alloc] init];
webView.frame = CGRectMake(0, 0, width, height);
[webView loadData:svgData MIMEType:@"image/svg+xml" textEncodingName:@"UTF-8" baseURL:baseUrl];


由于上述使用方式在iOS中是非常不方便的,现在一般大多采用SVGKit这个框架来处理和显示SVG格式的图片。[官方地址](https://github.com/SVGKit/SVGKit)

首先使用pod引入类库
pod 'SVGKit'
然后在代码中需要显示的图片的地方:
NSString  *svgName = @"jia";
SVGKImage *svgImage = [SVGKImage imageNamed:svgName];
SVGKLayeredImageView *svgView = [[SVGKLayeredImageView alloc] initWithSVGKImage:svgImage];
svgView.backgroundColor = [UIColor clearColor];
[self.view addSubview:svgView];
svgView.frame = CGRectMake(100, 200, 44, 44);

SVG format size of the picture contrast, generally will be retained in iOS now two kinds of image resolution, known as 2 times and 3 times the FIGS FIG. If you use the SVG format picture, then you only need a picture of. Here are two pictures of the format size comparison. This use is a cross icon, for example.

 

If you simply to compare the size of the words, SVG format images will not occupy too much advantage, since there is the picture of this format, there is a reasonable line of thinking to explore, the SVG format picture in the end what advantage?

 

Baidu Encyclopedia gave out several features of SVG format, here a brief outline. I think the size advantage and a large map display may be quite obvious, for a small map, we are currently exploring the above does not show up how small the volume in terms of volume.

 

Format advantages: 1, based on xml 2, the object 3 will be described using text, interactive and dynamic 4, fully supported dom

 

Comparative advantages: 1, any scaling 2, 3 independent text, smaller files (generally speaking, SVG files than GIF and JPEG files that are much smaller) 4, super display (SVG images on the screen are always edge clearly, it is suitable for any definition screen resolution and the print resolution.) 5, super color control (SVG image providing 1 of 6,000,000 kinds of color palette) 6, interactive and intelligent.

 

Guess you like

Origin www.cnblogs.com/lijinfu-software/p/11842687.html