我的崩溃仅发生在4S(而不是3GS)上。我怀疑是因为@ 2x。基本上我得到图像的原始字节并进行操作。这是我的问题。
我按照下面的示例代码中所述加载图像。最后,uiWidth应该为2000,cgwidth应该为2000。对吗? (如果从相机胶卷加载图像,这仍然是正确的吗?或者它的自动缩放和uiWidth将为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);
感谢您的帮助。
最佳答案
size
报告的UIImage
以磅为单位,而不是像素。您需要考虑scale
的UIImage
属性。
换句话说,如果test.jpg
为1000x1000,则UIImage.size
将报告1000x1000。如果test@2x.png
是2000x2000,那么UIImage.size
也会报告1000x1000。但是在第二种情况下,UIImage.scale
将报告2。CGImageGetWidth
报告其宽度(以像素为单位),而不是点。
关于ios - iPhone 4s-UIImage CGImage图像尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13131911/