为什么矢量化 PDF 图像具有分辨率属性 [英] Why Vectorized PDF images have a resolution property

查看:29
本文介绍了为什么矢量化 PDF 图像具有分辨率属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am a bit confused why would a vectorized image have a resolution property? Shouldn't it be vectorized and gives you any size?

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

Ok, I made a little test on Xcode and printed the width and the height of a pdf image. I noticed its 3 multiplied by the resolution. (Tested on 3x device screen).

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

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

As you may know, at compile time Xcode generates the 1x, 2x and 3x images from the PDF image. Those image sizes are decided by Xcode depending on the resolution of the PDF image. Which adds up with the results of the test.

我能否断定 pdf 图像的分辨率需要与 1x 设备模板上的像素大小相同?生成的图像会被像素化吗?

Can I conclude that the pdf images need to be in a resolution of the pixel size of it on a 1x device template? What about the generated images are they going to be pixelised?

此外,pdf 的分辨率不应比所需的 1x 尺寸高很多,否则它们可能会影响内存.对吗?

Also, the pdfs shouldn't have a resolution a lot higher than the wanted 1x size otherwise they might have a memory implications. right?

推荐答案

PDF 是矢量——有点像.您仍然可以在 PDF 中包含光栅元素(例如嵌入图像,有时还有阴影),对于此类图像,您仍应使用 PNG.否则你是正确的,当苹果第一次向资产目录(iOS8)添加 PDF 支持时,PDF 将在编译时被光栅化.事实证明,这并不总是可取的,因为有时您希望能够在同一个应用程序中以不同的点大小(不仅仅是像素大小)使用相同的矢量资产,因此他们添加了保留矢量数据"的选项(iOS 11).如果您选中此项,则资产会保存为 pdf 格式,并且光栅化会延迟到您要求为止.

PDF is vector -- sort of. You can still have raster elements in the PDF (embedded images, and sometime drop shadows for instance) and for such images you should still be using PNG. Otherwise you are correct in that when apple first added PDF support to the asset catalog (iOS8), the PDF's would be rasterized at compile time. It turns out that this isn't always desirable because sometimes you want to be able to use the same vector asset at different point sizes (not just pixel sizes) in the same app, so they added the option to "preserve vector data" (iOS 11). If you check this then the asset gets saved a pdf and rasterization is deferred until you ask for it.

所以回答你的两个问题:

So to answer your two questions:

  1. 您的 pdf 应该是您想要的 大小(不是像素大小)(即 1x),系统将始终根据屏幕比例(即 1x、2x、3x 或将来可能还有别的东西).
  2. 如果您使用保留矢量数据"并且您的 pdf 没有光栅元素,那么就内存而言,它的点大小应该无关紧要(矢量的大小将与曲线的复杂性成正比)pdf 而不是它的像素大小).然而,一旦它被光栅化,它确实会占用与光栅化图像大小成正比的内存.
  1. Your pdf should be in the point size (not pixel size) that you want (ie 1x) and the system will always scale it according to the screen scale (ie 1x,2x,3x or possibly something else in the future).
  2. If you use "preserve vector data" and your pdf has no raster elements then it shouldn't matter what point size it is as far a memory goes (the size of the vector will be proportional to the complexity of the curves in the pdf and not its pixel size). However, once it's rasterized it will indeed take up memory proportional to the size of the rasterized image.

这篇关于为什么矢量化 PDF 图像具有分辨率属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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