IOS Pixel Alignment Concept resolution _ios

Source: Internet
Author: User

In iOS, there is a concept called pixel alignment, if the pixel is not aligned, then in the GPU rendering, the need for interpolation calculation, the interpolation calculation process will have performance loss.

On the emulator, there is an option to display the pixels that are not aligned.

logical pixels and physical pixels

On iOS devices, there is the concept of point (logical pixel) and the concept of pixel (physical pixel).
When the program is in use, point is used and the actual rendering is pixel. A point can correspond to multiple pixel.
The ratio of point and pixel can be made by [[UIScreen mainscreen] scale] .

the scale concept of uiimage

If you load an image from a file whose name includes the @2x modifier, the scale are set to 2.0. You can also specify the 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 to the image ' s current orientation to account. Multiply the size values by the ' value in the scale ' to get the pixel dimensions of the image.

This means that the size of the image is multiplied by the image and scale to get the physical pixel.

Problem

So pixel misalignment refers to physical pixels (pixel) and logical pixel (point) alignment?

Experiment

Use 300*225 pixels for PNG pictures. Use different methods to load into memory, get different size and scale, and then put in different size imageview. Use the color misaligned images to determine if the pixel is aligned.
Here the simulator uses the iphone 6, the screen scale is 2.

Part of the 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 (M, imageView.bounds.size.width * 2/3, ImageView.bounds.size.height * 2/3);
  Imageview.frame = CGRectMake (M, ImageView.bounds.size.width, imageView.bounds.size.height);
  NSLog (@ "ImageView frame%@", [Nsvalue valueWithCGRect:imageView.frame]);
  [Self.view Addsubview:imageview];

Conclusion
1. The so-called pixel alignment, refers to the physical pixel alignment.
2. If the 2x image is placed on the 3x screen (6SP), the pixel misalignment will also occur.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.