iphone 4s - UIImage CGImage 图像尺寸 [英] iphone 4s - UIImage CGImage image dimensions

查看:31
本文介绍了iphone 4s - UIImage CGImage 图像尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的崩溃只发生在 4S(而不是 3GS)上.我怀疑它是因为@2x.基本上我得到图像的原始字节并进行操作.这是我的问题.

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.

我加载了下面示例代码中提到的图像.最后,uiWidth 应该是 2000,cgwidth 应该是 2000.对吗?(如果图像是从相机胶卷加载的,它仍然是真的吗?或者它的自动缩放和 uiWidth 将是 4000?)

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);

感谢您的帮助.

推荐答案

UIImage 报告的 size 以点为单位,而不是像素.您需要考虑 UIImagescale 属性.

The size reported by UIImage is in points, not pixels. You need to take into account the scale property of UIImage.

换句话说,如果 test.jpg 是 1000x1000,那么 UIImage.size 将报告 1000x1000.如果 test@2x.png 是 2000x2000,那么 UIImage.size 也会报告 1000x1000.但是在第二种情况下,UIImage.scale 会报告 2.

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 以像素为单位报告其宽度,而不是点.

CGImageGetWidth reports its width in pixels, not points.

这篇关于iphone 4s - UIImage CGImage 图像尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆