Image resolution and pixel alignment in iOS development, and pixel alignment in ios resolution

Source: Internet
Author: User

Image resolution and pixel alignment in iOS development, and pixel alignment in ios resolution
Concept of pixel alignment

In iOS, there is a concept called pixel alignment. If the pixels are not alignment, interpolation is required during GPU rendering. This interpolation process may cause performance loss.
On the simulator, there is an option to display the non-alignment of pixels.
Logical and physical pixels

On iOS devices, there are the concept of point (logical pixel) and pixel (physical pixel.
During programming, point is used, and pixel is used for actual rendering. A point can correspond to multiple pixel entries.
The ratio of point to pixel is[[UIScreen mainScreen] scale].

UIImage scale Concept

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 also has the concept of 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.

That is to say, the size of the image is multiplied by the size of the image and the scale to obtain the size of the physical pixel.

Problem

If pixels are not aligned, what is the physical pixel (pixel) and logical pixel (point) alignment?

Lab

Use a png Image of 300*225 pixels. Load the data to the memory using different methods to get different size and scale, and then store the data in the imageview of different size. Usecolor misaligned imagesTo determine whether the pixels are aligned.
Here the simulator uses the iPhone 6 and the screen scale is 2.

Image size Image scale Imageview Size Misalign?
300,225 1 300,225 Yes
300,225 1 150,112.5 No
150,112.5 2 150,112.5 No
150,112.5 2 75, 56.25 Yes
Some code
    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];
Conclusion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.