SVG图像文件的android [英] svg image files android

查看:473
本文介绍了SVG图像文件的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是低于code渲染SVG图像的ImageView在我的Andr​​oid应用程序

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());

链接: HTTP://$c$c.google。 COM / p / SVG-的Andr​​oid /维基/教程
其工作罚款。但是,图像的大小为2 MB(相同的图像是PNG格式只是少数KBS)。我有很多这样的图像。这增加了我的应用程序的内存。

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.

所以,我想在SVGZ格式使用图像的思想(COM pressed SVG)。谁能告诉我如何呈现SVGZ图像就可以直接在android系统的示意图。请帮忙。还建议我调整图像到不同的屏幕尺寸,不同的文件格式比SVN,使这个容易。

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.

推荐答案

是正确的。如果您正在分发它作为APK的一部分,因为它似乎你,这将是COM $ P $反正pssed,所以没必要COM preSS一遍。

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.

如果您想从远程资源加载它,你可以调用解析器之前包装在GZIPInputStream你的InputStream。

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;
}

要解决第二个问题,你放弃SVG又一文件格式之前,这是值得研究的,如果你的SVG可以优化,使得它是一个更容易接受的大小。有关SVG的优化思路看回答这个问题如果你的SVG仍然是很大的,通常要做的事情就是依傍多个PNG图像每一项决议。

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.

这篇关于SVG图像文件的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆