I have a crash which only occurs on 4S (not on 3GS). I am doubting its because of @2x. Basically I get raw bytes of image and manipulate. Here's the question I have.
I load a image as mentioned in the sample code below. At the end, uiWidth should be 2000 and cgwidth should be 2000. Correct? (Would it still be true if image is loaded from camera rolls? Or its autoscaling and uiWidth will be 4000?)
//test.jpg is 2000x 1500 pixels.
NSString *fileName = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:fileName];
int uiWidth = image.size.width;
CGImageRef cgimg = image.CGImage;
int cgWidth = CGImageGetWidth(cgimg);
Thank you for your help.
The size
reported by UIImage
is in points, not pixels. You need to take into account the scale
property of UIImage
.
In other words, if test.jpg
is 1000x1000 then UIImage.size
will report 1000x1000. If test@2x.png
is 2000x2000 then UIImage.size
will also report 1000x1000. But in the 2nd case, UIImage.scale
will report 2.
CGImageGetWidth
reports its width in pixels, not points.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.