svg image files android

有些话、适合烂在心里 提交于 2019-12-11 02:29:59

问题


I am using the below code to render svg images to imageview in my android application

    ImageView imageView = new ImageView(this);  
    final SVG svg = SVGParser.getSVGFromAsset(getAssets(), "start_4_480.svg");
   imageView.setImageDrawable(svg.createPictureDrawable());

link : http://code.google.com/p/svg-android/wiki/Tutorial Its working fine. But the size of an image is 2 MB(the same image is just few kbs in png format). I have lot of images of this kind. This increases the memory of my application.

So I want thought of using images in svgz formats(compressed svg). Can anyone tell me how to render svgz images directly to an image view in android. Please help. Also suggest me other ways of adapting images to different screen sizes and different file formats other than svn that makes this easy.


回答1:


his is right. If you are distributing it as part of the APK, as it appears you are, it will be compressed anyway, so no need to compress it again.

If you want to loading it from a remote resource, you can wrap your InputStream in a GZIPInputStream before calling the parser.

public static SVG getSVGZFromInputStream(InputStream is) throws SVGParseException {
   SVG svg = null;

   try {
      GZIPInputStream gis = new GZIPInputStream(is);     
      svg = SVGParser.getSVGFromInputStream(gis);
   } catch (IOException e) {
      //handle IO error
   }

   return svg;
}

To address your second question, before you abandon SVG for yet another file format, it is worth investigating if your SVG can be optimized to make it is a more acceptable size. For ideas on SVG optimization see the answer to this question If your SVG is still to big, the usual thing to do is fall back on multiple PNGs for each resolution.



来源:https://stackoverflow.com/questions/13722402/svg-image-files-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!