iphone 4s - UIImage CGImage image dimensions

早过忘川 提交于 2019-12-11 05:08:38

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/13131911/iphone-4s-uiimage-cgimage-image-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!