默认情况下,UIImageView在UIImageView中将图像显示为1px的image = 1pt,但我想显示为2px的image = 1pt。如何在UIImageView中显示高分辨率图像
以名称“.. @ 2x ..”保存图像的版本不适合,图像不保存在文件系统中。
例如,图像大小为400x100,我想要在显示中心显示图像,它应该是左侧120磅和右侧120点(640-400)/ 2
默认情况下,UIImageView在UIImageView中将图像显示为1px的image = 1pt,但我想显示为2px的image = 1pt。如何在UIImageView中显示高分辨率图像
以名称“.. @ 2x ..”保存图像的版本不适合,图像不保存在文件系统中。
例如,图像大小为400x100,我想要在显示中心显示图像,它应该是左侧120磅和右侧120点(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缩放图像。
您可以使用这样的事情:
NSData *data = //your data, however you get that...
UIImage *image = [UIImage imageWithData:data];
if ([UIScreen mainScreen].scale > 1.0f)
{
image = [UIImage imageWithCGImage:image
scale:[UIScreen mainScreen].scale
orientation:UIImageOrientationUp]
}
也许你应该根据图像大小调整UIImageView的框架。 – 2012-07-16 09:21:25
我无法更改UIIMageView的框架。 UIImageView的内容模式是UIViewContentModeCenter。 例如,图像大小为400x100,我想在显示中心显示它,图像的左侧和右侧有120 pt。 (640-400)/ 2 – George 2012-07-16 09:24:16
您是否尝试在文件名的末尾添加“@”符号?像保存到文件系统时的“myfile @ test.meta @”一样? – Eugene 2012-07-16 09:25:30