IOS notes on image-to-pixel Conversion

Source: Internet
Author: User

IOS notes on image-to-pixel Conversion

No matter how the image is generated, it is read from the disk, obtained from other objects, or obtained from the current video memory.

Whether it is a similar image, UIImage or CGImage.

The Display dimensions are divided into two types: point-based and pixel-based.

If you find that the generated image has a "screen" when you draw, scale, or take an image, most of them are incorrect image sizes.

For UIImage, we can use img. scale to obtain the actual pixel-to-vertex ratio. For CGImageRef, we can use the following method to obtain the actual pixel size:

CGSize size = CGSizeMake (CGImageGetWidth (imgRef), CGImageGetHeight (imgRef ));

Up to now, there are three types of image ratios on the iPhone: @ 1x, @ 2x, and @ 3x. The specific device is also very simple. You can search for them online.

In addition, it should be noted that some functions help you solve the point-to-pixel ratio conversion, so you do not have to handle it yourself, for example, take the following:

Uigraphicsbeginimagecontextwitexceptions (CGSizeMake (sz. width/2, sz. height), NO, 0 );

Note that the last parameter is 0, indicating that the actual size is automatically processed.

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.