默认情况下,UIImageView 在 UIImageView 中显示他的图像为 1px of image = 1pt,但我想显示为 2px of image = 1pt。
用名称“..@2x..”保存图像的版本不合适,图像未保存在文件系统中。
比如图片尺寸是400x100,我想把图片显示在屏幕中央,应该是图片左边120pt,右边120pt(640-400)/2
最佳答案
这很简单,请注意,对于低于 iOS 4 的版本,您没有 Retina 显示屏,这就是为什么在图像缩放方法中我首先进行此检查的原因:
//Retina detect
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){
然后从某个地方(文件、缓存等)加载image
,我正在以这种方式缩放它
UIImage * image2Xscaled = [UIImage alloc];
image = [[image2Xscaled initWithCGImage:[image CGImage] scale:2.0 orientation:UIImageOrientationUp] autorelease];
方法
initWithCGImage:scale:orientation:
适用于 iOS 4.0。这就是为什么你需要第一次检查。如果不支持销售,返回 1.0 缩放的图像。
关于iphone - 如何在 UIImageView 中显示高分辨率图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11501364/