iphone - 如何在 UIImageView 中显示高分辨率图像

标签 iphone objective-c ios

默认情况下,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/

相关文章:

iphone - 移动包含 UIButtons 的 UIView 会使这些按钮停止响应点击

iphone - iOS - 管理 IBOutlets 内存的最佳方式是什么?

ios - 此版本的 Xcode 不支持 IOS 文档的自动布局

iphone - 从 iPhone 应用程序构建 .doc 文件

c# - APNS APPLE C# sslstream 响应

iphone - 如何制作像iOS一样的清晰按钮

objective-c - 使用 CGImageCreate 的 32 位/组件图像实际上只有 8 位/组件

php - PHP 和智能手机设备之间的密码验证

objective-c - 向 CGPoint 类型参数发送 nil

objective-c - 为什么 Objective-C block 在不将其复制到堆中的情况下仍然有效?