gpt4 book ai didi

iphone - MKMapView renderInContext - iPhone 4 (Retina) 问题

转载 作者:IT王子 更新时间:2023-10-29 08:19:20 25 4
gpt4 key购买 nike

我有一个大小为 64x64 的 MKMapView。我正在使用“renderInContext:”方法从 map View 创建图像。并将图像分配给 UITableViewCell 的 imageView。在普通 iPhone 中,它显示的图像是正确的。但在 iPhone(Retina) 中显示图像模糊。我在模拟器中测试这个,而不是在实际设备中。我附上了下面的屏幕截图。

alt text

左侧的缩略图,带有圆角的是 UITableViewCell 的 imageView。右边的缩略图是MKMapView。

我正在使用以下代码从 map View 中获取图像。

UIGraphicsBeginImageContext(CGSizeMake(64, 64));
CGContextRef context = UIGraphicsGetCurrentContext();
[[mapView layer] renderInContext:context];
thumbnail_image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

为什么在 iPhone(Retina) 中会发生这种情况?如何解决这个问题?

最佳答案

正如 previous answer I gave 中已经提到的那样:

使用 UIGraphicsBeginImageContextWithOptions 代替 UIGraphicsBeginImageContext:

UIGraphicsBeginImageContextWithOptions(CGSizeMake(64, 64), NO, 0.0);

参见 QA1703更多细节。它说:

Note: Starting from iOS 4, UIGraphicsBeginImageContextWithOptions allows you to provide with a scale factor. A scale factor of zero sets it to the scale factor of the device's main screen. This enables you to get the sharpest, highest-resolustion snapshot of the display, including a Retina Display.

关于iphone - MKMapView renderInContext - iPhone 4 (Retina) 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4603457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com