iPhone4:阻止UIImageView缩放

发布于 2024-09-30 10:42:16 字数 396 浏览 0 评论 0原文

我正在下载大量图像以向用户显示。
每个图像的尺寸均为 512x512。

在正常分辨率的 iPhone 中,一切正常,
但在 iPhone4 中,它们看起来是按比例缩放的。

如果此图像是从资源中获取的,
我只需在图像名称中添加一个 @2x 即可,一切正常,
问题是这些图像是从网络动态加载的。

如何防止 UIImageView 在视网膜显示屏上放大?

编辑: 以下是屏幕截图:

谢谢大家。

I'm downloading a lot of images to display to the user.
Each of this images have 512x512.

In a normal resolution iPhone, everything works fine,
but in the iPhone4, they appear scaled.

If this images were being fetched from the resources,
I would simply add a @2x to the image name and everything would work,
the problem is that this images are dynamically loaded from the web.

How can I prevent this UIImageViews from scaling up on the retina display?

EDIT:
Here are the sreenshot:

Thank you all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

時窥 2024-10-07 10:42:16

看看这段代码 - 当我想控制图像是否以scale=2或scale=1加载时,我在 UIImage 类别中使用它...查看 NSData 获取文件内容的位置(在我的代码中)并替换使用从网络获取图像的代码:

if ( [[[UIDevice currentDevice] systemVersion] intValue] >= 4 && [[UIScreen mainScreen] scale] == 2.0 ) {
    if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) {
        return [self initWithCGImage:[[UIImage imageWithData:[NSData dataWithContentsOfFile:path]] CGImage] scale:2.0 orientation:UIImageOrientationUp];
    }
} else [ load here the image via imageWithContentsOfFile or whatever ]

因此,技巧在于 UIImage 类的“initWithCGImage”的“scale”参数中,如果要加载高分辨率图像,则传递 2.0;如果要加载低分辨率图像,则传递 1.0 - 这就像您对高分辨率图像加载的最大控制。

最好的,马林

look at this code - I use it in a UIImage category when I want to control whether the image would be loaded with scale=2 or scale=1 ... See where NSData fetches the content of the file (in my code) and replace with your code that fetches images from the web :

if ( [[[UIDevice currentDevice] systemVersion] intValue] >= 4 && [[UIScreen mainScreen] scale] == 2.0 ) {
    if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) {
        return [self initWithCGImage:[[UIImage imageWithData:[NSData dataWithContentsOfFile:path]] CGImage] scale:2.0 orientation:UIImageOrientationUp];
    }
} else [ load here the image via imageWithContentsOfFile or whatever ]

So the trick is in the "scale" parameter of the "initWithCGImage" of the UIImage class, pass 2.0 if you are loading hi res images, or pass 1.0 if you are loading low res images - that's like the greatest control you take over the hi res image loading.

best, Marin

妄想挽回 2024-10-07 10:42:16

也许尝试检查设备是否有视网膜显示屏,以及是否尝试缩小图像。您可以通过以下方式查看它是否具有视网膜显示屏:

    if ( [[[UIDevice currentDevice] systemVersion] intValue] >= 4 && [[UIScreen mainScreen] scale] == 2.0 ) {
  //do the scaling of image(s)
}

让我知道这是否有效。

Maybe try to check if the device has retina display and if it does try scaling the image down. You can see if it has retina display with:

    if ( [[[UIDevice currentDevice] systemVersion] intValue] >= 4 && [[UIScreen mainScreen] scale] == 2.0 ) {
  //do the scaling of image(s)
}

Let me know if that does the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文