如何使用CGImageCreateWithImageInRect for iPhone 4(HD)? [英] How use CGImageCreateWithImageInRect for iPhone 4 (HD)?
问题描述
我使用以下代码从精灵中获取图像。除了iPhone 4(高清版)外,它在任何地方都能正常工作。
I use the following code to getting images from the sprite. And it works fine everywhere except the iPhone 4 (HD version).
- (UIImage *)croppedImage:(CGRect)rect {
CGImageRef image = CGImageCreateWithImageInRect([self CGImage], rect);
UIImage *result = [UIImage imageWithCGImage:image];
CGImageRelease(image);
return result;
}
iPhone 4自动加载图像的高清版本(sprite@2x.png )而不是sprite.png。原始图像具有比例2,但结果图像具有比例1和错误的大小。
The iPhone 4 automatically load HD version of the image (sprite@2x.png) instead sprite.png. The original image has a scale 2, but the resulting image has a scale 1 and wrong size.
如何考虑到iPhone 3G的不同比例来处理此行为[ s]和iPhone 4?
How to handle this behavior taking into account the different scales for iPhone 3G[s] and the iPhone 4?
我读过这个文档,但关于使用 CGImageCreateWithImageInRect 这里什么也没说。
I have read this document, but about the use CGImageCreateWithImageInRect here says nothing.
推荐答案
我可以告诉CGImageCreateWithImageInRect会做正确的事情。你需要改变的是UIImage的启动
From what I can tell the CGImageCreateWithImageInRect will do the right thing. What you need to change is the UIImage initilization
将其更改为 [UIImage imageWithCGImage:图像比例:self.scale orientation:self。 imageOrientation]
它应该可以正常工作。 (假设这是UIImage上的类别,它看起来像是)
Change it to [UIImage imageWithCGImage:image scale:self.scale orientation:self. imageOrientation]
and it should work just fine. (this is assuming this is a category on UIImage which it looks like it is)
这篇关于如何使用CGImageCreateWithImageInRect for iPhone 4(HD)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!