iphone 4 - hires image loading with twice the size
I have 3 versions of an image: "myImage~ipad.png", "myImage~iphone.png" and "myImage@2x~iphone.png".
Obviously, the last one has twice the size of the second.
I am loading them开发者_Go百科 using
UIImage *imageU = [UIImage imageNamed:@"myImage.png"];
UIImageView *myView = [[UIImageView alloc] initWithImage:imageU];
[self.view addSubview:myView];
[myView release];
the image loads fine on the iPad and 3G/3GS but not on iPhone 4, where it appears huge, with twice the size. iPhone 4 is doubling the size of "myImage@2x~iphone.png" ??? (!!!)
What can be wrong?
thanks.
Unbelievable! another bug or bad document stuff by apple.
This is what the docs say:
Updating Your Image Resource Files
Applications running in iPhone OS 4 should now include two separate files for each image resource. One file provides a standard-resolution version of a given image, and the second provides a high-resolution version of the same image. The naming conventions for each pair of image files is as follows:
Standard: ImageName device_modifier . filename_extension
High resolution: ImageName @2x device_modifier. filename_extension
The and portions of each name specify the usual name and extension for the file. The portion is optional and contains either the string ~ipad or ~iphone. You include one of these modifiers when you want to specify different versions of an image for iPad and iPhone. The inclusion of the @2x modifier for the high-resolution image is new and lets the system know that the image is the high-resolution variant of the standard image.
So, according to the docs you should name your images as I did: "myImage~iphone.png" (lores), "myImage@2x~iphone.png" (hires) and "myImage~ipad.png" (ipad).
Due to bad documented docs (as usual with their docs) and buggy SDK, this is the reality:
- you should name your files as "myImage~iphone.png" (lores), "myImage~iphone@2x.png" (hires) and "myImage.png" (ipad).
IN OTHER WORDS: PUT THE @2X AT THE END, not in the middle as recommended by Apple and DON'T PUT ANY TILDE STUFF on the iPad images. But this is not all: even if you do all this, you will only be able to load your images using [UIImage imageNamed:...], that means all your images will be cached. This is because ImageWithContentsOfFile doesn't work on the SDK 4, even being stated on the docs it does.
The complete solution involves using THIS STUFF.
Thanks Apple for this half-cooked stuff.
update to this answer: It shows that I am right after all. This is a bug. I have reported it to apple on July 8 and today I received this message from them: "This is a follow up to Bug ID# 8161396. After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 8084451."
It does not, you are doing something wrong, check the rect of the imageview, a @2x image on iphone4 has the same coordinate points and size as the smaller image on older phones
NSLog(@"%f %f %f %f",myView.frame.origin.x,myView.frame.origin.y,myView.frame.size.width,myView.frame.size.height);
精彩评论