UIImagePNGRview () and Scale (iPhone 4 Screen)

I have an image generation code that uses UIGraphicsBeginImageContext (), UIGraphicsGetImageFromCurrentImageContext () and UIImagePNGRepresentation () to execute some drawing, and then save it to disk as PNG for later use.

Does the UIImagePNGRview () scale? As if I have an image with a width of 20 pixels, will PNG get 20 pixels or 40 pixels?

In addition, when I display these images, I use [UIImage imageWithContentsOfFile:] and [image drawInRect:]. Is there any way to hint at these methods for using a higher resolution drawing?

+6
iphone cocoa-touch uikit ios4 iphone-4
source share
1 answer

In the iPhone Application Programming Guide, you should use UIGraphicsBeginImageContextWithOptions with a scale of 2.0 to create a properly scaled context for iPhone 4.

Regarding the second part of your question, I believe that you should save the resulting png with the suffix @ 2x to the base name (for example, myImage@2x.png ). Then, when you download it back using UIImage, its size and scale will be set correctly. Otherwise, your image will be uploaded on a scale of 1.0 and will be twice as large (in points) as you expect. This section of the same document details high-resolution images for devices with high-resolution displays.

+6
source share

All Articles