Ios4 supports high-resolution Summary

Source: Internet
Author: User
Ios4 supports high-resolution Summary

14:16:06 tags: IOS 4, iPhone 4, retina, original works, allowed to be reproduced. During reprinting, please be sure to mark the original source, author information, and this statement in the form of hyperlinks. Otherwise, legal liability will be held. Http://life173.blog.51cto.com/2035365/384735

IPhone 4 uses a screen called retina. The size is as big as that of the old iPhone, but the resolution is increased by 4 times. It looks too good to see the high-definition image, and there is no pixel at all. for the old app, running in iPhone 4 will automatically replace the original pixel with four pixels, so that the Code does not need to be changed, so that the old app can run in iPhone 4 naturally, however, the UI effect will be a bit masked, not the best effect. To achieve the best, you must re-design a 640*960 HD version for the original image resources, in this way, the best UI effect can be achieved in iPhone 4 ~ The following is a brief summary of how to use a high-definition image in ios4. First, we need to understand some concepts:Points versus pixels:When using native drawing technologies such as quartz, uikit, and core animation, you specify coordinate values using a logical coordinate space, which measures distances in points. this logical coordinate system is decoupled from the device coordinate space used by the system frameworks to manage the pixels on the screen. generally, the size used in the program is calculated by point. in the old iPhone, point and pixel are hardly distinguished, because they are both and 320*480. but in iPhone 4 or later devices, this is no longer a relationship. For iPhone 4's Retina screen, 1 point = 2 pixels, the maximum screen point size is still 320*480.Next, let's talk about how to use a high-definition image:The hypothetical picture default.png (320*480 then and default@2x.png (640*960) uiimage * image1 = [uiimage imagenamed: @ "default.png"];
Uiimage * image2 = [uiimage imagenamed: @ "default"];

The above two lines of code automatically match the image in ios4 based on the resolution of your mobile phone. For iPhone and iPhone, image 1 and image 2's are all converted to default.png (320*480). The image size is displayed, you will find that the value is 320*480 (based on the point). Then, we can see that the scale property of the image is 1.0, indicating that the actual piont corresponds to a pixel, so the actual pixel of the image is (320 * scale) * (480 * scale) = 320 * 480.if the iPhone 4 returns the result, both the imageids are defa@@2x.png (640*960), and check the image size again, you will find that it is still 320*480 (points), but scale is 2.0, indicating that one point corresponds to two pixels on the image, so the actual pixel of the image is (320 * scale) * (480 * scale) = 640*960.Therefore, you only need to add the suffix @ 2x to a high-definition image with the same name. You can use the imagenamed function of uiimage to call the image name (without the suffix @ 2x) and then automatically call the appropriate image, easy to use.You can also use the initwithcontentsoffile of the uiimage: (signature.You can perform the following tests to deepen your impression:Default.png (320*480 million, default@2x.png (640*960 million, defacopycopy.png (320*480 million (640*960) Four images are called using imagenamed: And initwithcontentsoffile: (directly call each file name: default.png,default@2x.png, defaultcopy.png, Default_Copy@2x.png), and then show the effect on the iPhone 3G and iPhone 4, by the way, the output image size and scale to compare. will have a better understanding of this problem. for example, if the image of iPhone 4 was changed to default.png by imagenamed, the returned result is defa@@2x.png (640*960 bytes (320*480). The size is 320*480, but the scale is 1.0. The actual image pixel is (320 * scale) * (480 * scale) = 320*480, the display effect is poor, because the image pixel is only 1/4 of the HD.

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.