简体   繁体   English

使用PDF或Vector文件在Android Studio中添加所有大小的图像资产

[英]Add all sizes of image asset in Android Studio with a PDF or Vector file

In iOS development with Xcode it is really convenient because you can add an image asset or launcher icon with one .pdf file and it generates all the necessary sizes automatically. 在使用Xcode的iOS开发中,这非常方便,因为您可以添加带有一个.pdf文件的图像资产或启动器图标,并且它会自动生成所有必需的尺寸。 The .pdf file can be created with Adobe Illustrator or a similar program that makes vector graphics. 可以使用Adobe Illustrator或制作矢量图形的类似程序来创建.pdf文件。

Rather than sit there and export every size of icon/image asset one at a time, is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own? 有没有一种快速的方法可以向Android Studio添加矢量图像并让其自己填充所有相关尺寸的文件夹,而不是一次坐在那里并一次导出每种尺寸的图标/图像资产? Or in general, is there a way to accomplish the same thing in some way? 还是总的来说,有没有办法以某种方式完成同一件事?

I have seen other posts where people suggest using an online tool that takes your .png image and lets you download a .zip with all of the different image sizes, but by definition, that method will not result in crisp and high quality image assets. 我看过其他文章,人们建议使用一种在线工具来获取您的.png图像,并让您下载具有所有不同图像尺寸的.zip文件,但是根据定义,该方法不会产生清晰且高质量的图像资产。 You always want to go from a vector. 您总是想从向量开始。

is there a fast way to add a vector image to Android Studio and have it populate all of the relevant sized folders on its own? 有没有一种快速的方法可以将矢量图像添加到Android Studio并自行填充所有相关大小的文件夹?

Use File > New > Vector Asset in Android Studio 1.5 and higher. 在Android Studio 1.5及更高版本中使用文件>新建>矢量资产。 This will let you import an SVG file. 这将使您导入SVG文件。 Android Studio will attempt to convert it into a vector drawable resource , with varying degrees of success. Android Studio将尝试将其转换为矢量可绘制资源 ,并获得不同程度的成功。 If you are using a recent version of the Android Plugin for Gradle (1.5.0 or higher should work AFAIK), the build tools will also generate PNGs from the vector drawables for use on older devices (Android 4.4 and earlier). 如果您使用的是最新版的Android Gradle插件(1.5.0或更高版本应可使用AFAIK),则构建工具还将从矢量可绘制对象生成PNG,以供在较旧的设备(Android 4.4及更早版本)上使用。

but by definition, that method will not result in crisp and high quality image assets 但根据定义,该方法不会产生清晰且高质量的图像资产

You do not have much of a choice on older devices. 在较旧的设备上,您没有太多选择。 There are a few deprecated backports of VectorDrawable floating around that you can try to use, but Google abandoned theirs. 您可以尝试使用一些不推荐使用的VectorDrawable移植,但是Google放弃了它们。

You always want to go from a vector. 您总是想从向量开始。

Not necessarily. 不必要。 Please bear in mind that not everybody has high-end mobile devices. 请记住,并非所有人都有高端移动设备。 Rendering SVG or other vector artwork is comparatively expensive, which is why Android did not directly support it (and still does not directly support SVG itself). 渲染SVG或其他矢量插图的费用相对较高,这就是Android不直接支持SVG(并且仍然不直接支持SVG本身)的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM