为iOS应用加载基于SVG的图像资产 [英] Loading SVG based image assets for iOS app

查看:331
本文介绍了为iOS应用加载基于SVG的图像资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从thenounproject购买了一个图标作为SVG图像.然后,我使用一个名为 Gapplin 的macOS程序将此SVG导出为PNG图像.它显示为100x100像素的图像.

I purchased an icon from thenounproject as an SVG image. I then use a macOS program called Gapplin to export this SVG into a PNG image. It comes out as a 100x100 pixel image.

然后我使用预览"程序打开此PNG图像,然后转到工具"->调整大小"并创建10x10、20x20和30x30图像.然后,我在Xcode中将这些图像加载为1x,2x,3x.

I then open this PNG image with Preview program and go Tools -> Adjust Size and create 10x10, 20x20 and 30x30 images. I then load these images as 1x, 2x, 3x in Xcode.

这是正确的方法吗?

推荐答案

不是,这不是最佳解决方案.

No, it's not the optimal solution.

当然,您当前的解决方案是可行的,但这远非理想.这样做会失去(珍贵的!)图像质量(有关更多详细信息,请请参阅此处).您可以通过以下方式改善工作流程:

Your current solution works, of course, but it's far from ideal. You are losing (precious!) image quality in doing so (see here for more details). You can improve your worklflow by:

    从原始SVG文件中
  • 导出所有三种分辨率,确保您从基于矢量的图像源(使用Gapplin或其他图像应用程序)中获得最佳的PNG位图;

  • exporting all 3 resolutions from the original SVG file, ensuring you get the best possible PNG bitmap from a vector based image source (using Gapplin or some other image app);

转换将SVG转换为PDF,然后以Xcode导入PDF矢量图像文件(我上次检查时,Xcode 8仍然不直接支持SVG文件,因此我们暂时还只能使用旧的PDF).

or converting your SVG to PDF and then importing the PDF vector image file in Xcode (last time I checked, Xcode 8 still didn't have direct support for SVG files so we are stuck with good old PDF for now).

从图像质量角度来看,这两种方法都应产生非常相似的结果,并且相对于您当前的工作流程有所改进.

Both methods, image quality wise, should produce very similar results and are an improvement from your current workflow.

关于应用程序文件的大小,您应该再也不会从这两种方法中看到不同之处.即使使用最后一种方法,Xcode仍会在构建时生成所需的资产,因此,您的应用程序将携带与第一种方法相同的图像/图标集.

Regarding app file size, you shouldn't again see a difference from neither method. Even using the last method, Xcode still generates the required assets at build time and, as such, your app will be carrying around the same image/icon set as the first method.

这篇关于为iOS应用加载基于SVG的图像资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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