简体   繁体   English

iPhone的图片大小不正确-

[英]Image sizes for iPhone are incorrect-

I have this image called image.png - I have created it in the 3 differen't sizes. 我有一个名为image.png的图片-我创建了3种不同尺寸的图片。

  • image@3x.png - 1001x132px image@3x.png-1001x132px
  • image@2x.png - 668x88px image@2x.png-668x88px
  • image.png - 334x44px image.png-334x44px

What I dont understand is how come the @2x is 668px in width, when the iPhone 5&5S are only 640px wide? 我不明白的是,当iPhone 5&5S的宽度仅为640px时,@ 2x的宽度为668px?

I have designed the @3x using iPhone 6+ screen size. 我使用iPhone 6+屏幕尺寸设计了@ 3x。

Could someone please explain? 有人可以解释一下吗?

Let me explain you the difference between the iPhone screens, so you will understand the need of these @?x suffixes. 让我解释一下iPhone屏幕之间的区别,以便您了解这些@?x后缀的必要性。 The first iPhone, and the two after it (3G and 3GS) had the standard display with dimensions w:320, h:480 . 第一个iPhone及其后的两个(3G和3GS)具有标准显示,尺寸为w:320, h:480 With the introducing of iPhone 4, Apple also introduced the so called Retina display , which "packs" 4 physical pixels in 1 logical pixel (also called "point"), ie: 随着iPhone 4的推出,Apple还推出了所谓的Retina显示屏 ,该显示屏将4个物理像素“打包”为1个逻辑像素(也称为“点”),即: Retina显示屏

Now, even though the pixel dimensions of the iPhone 4 are w:640, h:960 (and iPhone 5/5C/5S w:640, h:1136 ), you still have screen size of w:320, h:480 points (respectively w:320, h:568 for 5/5C/5S). 现在,即使iPhone 4的像素尺寸为w:640, h:960 (和iPhone 5 / 5C / 5S w:640, h:1136 ),屏幕尺寸仍为w:320, h:480点(对于5 / 5C / 5S w:320, h:568分别为w:320, h:568 )。 But because the coordinate system of the display uses points instead of pixels, the dimensions and position in points of all UI elements remains the same for every device. 但是,因为显示器的坐标系使用点​​而不是像素,所以每个设备的所有UI元素的尺寸和位置均保持不变。

What about the prefixes? 前缀呢?

Now, the ratio between point and pixels is called "scale". 现在,点和像素之间的比例称为“比例”。 UIScreen, UIView, UIImage, and CALayer classes have a property called scale , and when you load image with prefix @2x , the scale will be 2.0 and the display will fit 2x2 bitmap pixels from the image in one point. UIScreen,UIView,UIImage和CALayer类具有一个名为scale的属性,当您加载带有@2x前缀的图像时,缩放比例将为2.0 ,并且显示将在一个点上适合图像中2x2位图像素。 iPhone 6+ uses the @3x suffix because of the Retina HD display, which has scaling factor 3 and the image is afterwards downscaled from rendered 2208 × 1242 pixels to 1920 × 1080 pixels (points on the screen). iPhone 6+使用@3x后缀,这是因为Retina HD显示屏具有缩放比例3 ,并且图像随后从渲染的2208×1242像素缩小为1920×1080像素(屏幕上的点)。

The downscaling ratio is 1920 / 2208 = 1080 / 1242 = 20 / 23. That means every 23 pixels from the original render have to be mapped to 20 physical pixels. 缩小比例为1920/2208 = 1080/1242 = 20 /23。这意味着原始渲染中的每23个像素必须映射到20个物理像素。 In other words the image is scaled down to approximately 87% of its original size. 换句话说,图像被缩小到原始大小的大约87%。

( source ). 来源 )。

Required image sizes 所需的图像尺寸

For example if you want to have an image of green circle in a black square with dimensions w:100, h:100 , you will need two more images: one with dimensions w:200, h:200 and one with w:300, h:300 , as the system will scale them according to the suffix. 例如,如果您要在黑色正方形中以w:100, h:100尺寸显示绿色圆圈的图像,则还需要另外两张图像:一张的尺寸为w:200, h:200 ,另一张的尺寸为w:300, h:300 ,因为系统将根据后缀对其进行缩放。 在此处输入图片说明

Where to go next 接下来去哪里

Here is some stuff to read (if I didn't explain it right or easy to understand). 这是一些要阅读的东西(如果我没有正确解释或不容易理解的话)。 My advice: check the link above and the official Apple documentation for further knowledge: 我的建议:检查上面的链接和Apple的官方文档,以了解更多信息:

Apple documentation: Supporting high-res devices Apple文档:支持高分辨率设备

Apple documentation: Points vs. Pixels Apple说明文件:点数与像素

@2x is using for retina display, like iphone 4, 4s, 5, 5s, 6, ipads .... The image has 668px in width, I think it use for a view that could have extra area for view, like horizontal scroll view, tutorial pages, or for ipad ... ... or something like that .. And yes, you're right about the width of retina display, it is just 640px. @ 2x用于视网膜显示,例如iphone 4、4s,5、5s,6,ipads...。图像的宽度为668px,我认为它用于的视图可能具有额外的显示区域,例如水平滚动视图,教程页面或ipad ...或类似的东西..是的,您对视网膜显示的宽度是正确的,它仅为640px。 Hope this may help. 希望这会有所帮助。

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

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