首页 > 解决方案 > 为什么矢量化 PDF 图像具有分辨率属性

问题描述

我有点困惑为什么矢量化图像具有分辨率属性?它不应该被矢量化并给你任何大小吗?

好的,我在 Xcode 上做了一个小测试,打印了一个 pdf 图像的宽度和高度。我注意到它的 3 乘以分辨率。(在 3 倍设备屏幕上测试)。

let imageRef = (imageView.image?.cgImage)!
let size = imageRef.bytesPerRow * imageRef.height
print(imageRef.width)
print(imageRef.height)

您可能知道,在编译时,Xcode 从 PDF 图像生成 1x、2x 和 3x 图像。这些图像大小由 Xcode 根据 PDF 图像的分辨率决定。这与测试结果相加。

我可以得出结论,pdf 图像需要在 1x 设备模板上具有像素大小的分辨率吗?生成的图像会被像素化吗?

此外,pdf 的分辨率不应高于所需的 1x 大小,否则可能会影响内存。正确的?

标签: iosswiftxcode

解决方案


It's simply a matter of how much work the asset catalog has to do in advance and how much work the system has to do at runtime. If your PDF is only for use at 1x, 2x, and 3x, the asset catalog can pre-render it when the app is built and so it takes no time at all for the runtime to draw it. But if you intend to show this PDF at other sizes, the runtime must perform that rendering. So you only preserve vector data in the latter case.


推荐阅读