Xcode 6 资产目录自动为较小比例创建图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25840012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 6 asset catalog automatically create images for smaller scales
提问by JonasG
With the need of 3x images in iOS 8 I figured it would be easier to manage images with an asset catalog in Xcode 6. I am trying to just provide a single image, the 3x scaled image to the asset catalog and I want Xcode to automatically downscale that image to generate 2x and 1x versions of the 3x image, so that I don't have to do it manually.
由于在 iOS 8 中需要 3x 图像,我认为在 Xcode 6 中使用资产目录管理图像会更容易。我试图只提供一个图像,3x 缩放图像到资产目录,我希望 Xcode 自动缩小该图像以生成 3x 图像的 2x 和 1x 版本,这样我就不必手动执行此操作。
Right now this is what I have:
现在这就是我所拥有的:
I really hope that Xcode has such a feature to automatically create 2x and 1x images and I just have not discovered it yet. If there isn't any such feature, are there any alternatives? (I know IconKit but it is annoying and hasn't been updated to support 3x images. If it was made properly in the first place it wouldn't even need an update..)
我真的希望 Xcode 有这样一个功能来自动创建 2x 和 1x 图像,只是我还没有发现它。如果没有任何此类功能,是否还有其他选择?(我知道 IconKit 但它很烦人,还没有更新以支持 3x 图像。如果它首先制作得当,它甚至不需要更新..)
I know that Xcode automatically can generate all images from a vector pdf, but thats not what I am looking for!
我知道 Xcode 可以自动从矢量 pdf 生成所有图像,但这不是我想要的!
回答by JonasG
I ended up making a small mac app that takes care of the dirty work. You can drag and drop one or multiple .jpg or .png files into the app's main view; it will detect the input image's scale and create the smaller scaled images. With this app I only need to create a single, 3x image and drag it into the app to create the two smaller images. It saves so much work!
我最终制作了一个小型 mac 应用程序来处理这些肮脏的工作。您可以将一个或多个 .jpg 或 .png 文件拖放到应用程序的主视图中;它将检测输入图像的比例并创建较小比例的图像。使用此应用程序,我只需创建一个 3x 图像并将其拖入应用程序即可创建两个较小的图像。它节省了很多工作!
The source can be found on my GitHub page, simply download it and run it on your mac! https://github.com/JonasGessner/ImageReducer
源代码可以在我的 GitHub 页面上找到,只需下载并在您的 Mac 上运行即可!https://github.com/JonasGessner/ImageReducer
回答by lukszar
There is another way to solve this problem.
还有另一种方法可以解决这个问题。
Use Automator to create Mac OS X service which create @3x, @2x and normal image on base of 1 image in @3x resolution automatically. It use just 3 methods: duplicate images, scale down, and rename.
使用 Automator 创建 Mac OS X 服务,该服务会自动以 @3x 分辨率在 1 张图像的基础上创建 @3x、@2x 和普通图像。它只使用 3 种方法:复制图像、缩小比例和重命名。
Ready Mac OS X service made in Automator you can find here:
您可以在此处找到 Automator 中的就绪 Mac OS X 服务:
回答by NSSwift
late to the party but there is one tool which make all assets @1x, @2x, @3x and icons for you in just one click. And also export to XCAssets file.
聚会迟到,但有一种工具可以一键为您制作所有资产@1x、@2x、@3x 和图标。并且还导出到 XCAssets 文件。
You can find it here: https://github.com/angelvasa/AVXCAssets-Generator
你可以在这里找到它:https: //github.com/angelvasa/AVXCAssets-Generator
Hope this will help someone
希望这会帮助某人
回答by Zev Eisenberg
If you do not provide 1x or 2x assets, and your app is run on a 1x or 2x device, it should downsample the 3x asset at runtime. This may look fine, but depending on the scaling method used, it may also look really bad, so make sure this is really what you want.
如果您不提供 1x 或 2x 资源,并且您的应用在 1x 或 2x 设备上运行,则应在运行时对 3x 资源进行下采样。这可能看起来不错,但根据所使用的缩放方法,它也可能看起来很糟糕,因此请确保这确实是您想要的。
回答by Albert Zhang
If a folder named *.imageset
, and the contents in it is well organized, Xcode will actually recognize them as an image. So this is another way to do this: https://github.com/albert-zhang/gen_xcassets
如果名为 的文件夹*.imageset
,并且其中的内容组织得很好,Xcode 实际上会将它们识别为图像。所以这是另一种方法:https: //github.com/albert-zhang/gen_xcassets
This python script will quickly auto generate @2x version for all images in a folder.
此 python 脚本将快速为文件夹中的所有图像自动生成 @2x 版本。