gpt4 book ai didi

iphone - 用于视网膜显示的 CoreGraphics

转载 作者:行者123 更新时间:2023-12-03 18:15:33 25 4
gpt4 key购买 nike

我使用以下代码对加载的图像执行一些操作,但我发现在视网膜显示屏上时显示变得模糊

- (UIImage*)createImageSection:(UIImage*)image section:(CGRect)section

{
float originalWidth = image.size.width ;
float originalHeight = image.size.height ;
int w = originalWidth * section.size.width;
int h = originalHeight * section.size.height;

CGContextRef ctx = CGBitmapContextCreate(nil, w, h, 8, w * 8,CGImageGetColorSpace([image CGImage]), kCGImageAlphaPremultipliedLast);
CGContextClearRect(ctx, CGRectMake(0, 0, originalWidth * section.size.width, originalHeight * section.size.height)); // w + h before
CGContextTranslateCTM(ctx, (float)-originalWidth * section.origin.x, (float)-originalHeight * section.origin.y);
CGContextDrawImage(ctx, CGRectMake(0, 0, originalWidth, originalHeight), [image CGImage]);
CGImageRef cgImage = CGBitmapContextCreateImage(ctx);
UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage];

CGContextRelease(ctx);
CGImageRelease(cgImage);

return resultImage;
}

如何更改它以使其兼容视网膜。

预先感谢您的帮助

最好,DV

最佳答案

CGImages 不会考虑您设备的视网膜特性,因此您必须自己考虑。

为此,您需要将 CoreGraphics 例程中使用的所有坐标和大小乘以输入图像的 scale 属性(在 Retina 设备上为 2.0),以确保您完成所有操作您以双分辨率进行操作。

然后您需要更改 resultImage 的初始化以使用 initWithCGImage:scale:orientation: 并输入相同的比例因子。这就是使 Retina 设备以原始分辨率而不是像素加倍分辨率渲染输出的原因。

关于iphone - 用于视网膜显示的 CoreGraphics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4707465/

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