IOS开发中像素对齐的详细简述

来源:爱站网时间:2020-12-26编辑:网友分享
在IOS开发中像素对齐需要进行插值计算,而这可能会导致性能的损失,那么IOS开发中像素对齐的详细简述,大家都清楚吗?感兴趣的小伙伴们参考看看吧!

在IOS开发中像素对齐需要进行插值计算,而这可能会导致性能的损失,那么IOS开发中像素对齐的详细简述,大家都清楚吗?感兴趣的小伙伴们参考看看吧!

在模拟器上,有一个选项可以把像素不对齐的部分显示出来。

逻辑像素与物理像素

在iOS设备上,有point(逻辑像素)的概念,以及pixel(物理像素)的概念。
 在编程序时,用的是point,实际渲染时用的是pixel。一个point可以对应多个pixel。
 point和pixel的比例是可以通过[[UIScreen mainScreen] scale]来制定。

UIImage的scale概念 

If you load an image from a file whose name includes the @2x modifier, the scale is set to 2.0. You can also specify an explicit scale factor when initializing an image from a Core Graphics image. All other images are assumed to have a scale factor of 1.0. 

image也有size的概念。

This value reflects the logical size of the image and takes the image's current orientation into account. Multiply the size values by the value in the scale property to get the pixel dimensions of the image. 

就是说image的size和image和scale相乘,得到物理像素的大小。

问题

那么像素不对齐指的是物理像素(pixel)和逻辑像素(point)对齐呢?

实验

使用300*225像素的png图片。分别使用不同的方法load到内存中,得到不同的size和scale,然后放在不同size的imageview里。使用color misaligned images来判定是否像素对齐。
 这里模拟器使用的iPhone 6,屏幕的 scale是2。

部分代码

  NSLog(@"screen scale is %f",[[UIScreen mainScreen] scale]);
  UIImage *image = [UIImage imageNamed:@"test.png"];
  NSLog(@"image size %@, scale %f ", [NSValue valueWithCGSize:image.size], image.scale);
  UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
//  imageView.frame = CGRectMake(50, 100, imageView.bounds.size.width * 2/3, imageView.bounds.size.height * 2/3);
  imageView.frame = CGRectMake(50, 100, imageView.bounds.size.width, imageView.bounds.size.height);
  NSLog(@"imageView frame %@", [NSValue valueWithCGRect:imageView.frame]);
  [self.view addSubview:imageView];

以上就是爱站技术频道小编介绍的IOS开发中像素对齐的详细简述,对于还不知道如何操作的人来说,一定要来js.aizhan.com学习哦。

上一篇:IOS开发中正则表达式的验证方法

下一篇:IOS开发中动画效果的示例

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载