我使用下面的代码从精灵图中获取图片。在除了iPhone 4 (高清版本)之外的所有地方都能正常工作。
- (UIImage *)croppedImage:(CGRect)rect {
CGImageRef image = CGImageCreateWithImageInRect([self CGImage], rect);
UIImage *result = [UIImage imageWithCGImage:image];
CGImageRelease(image);
return result;
}
iPhone 4会自动加载图像的高清版本(sprites@2x.png),而不是sprites.png。原始图像具有2倍缩放比例,但结果图像具有1倍缩放比例和错误的大小。
如何处理这种行为,并考虑iPhone 3G[s]和iPhone 4之间的不同缩放比例?
我已经阅读了这篇文档,但关于使用CGImageCreateWithImageInRect的内容没有提到。