我使用以下代码对加载的图像进行一些操作,但是发现在Retina屏幕上显示时变得模糊了
- (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;
}
如何更改此内容以使其支持Retina显示屏。
感谢您的帮助。
最好的祝福, DV
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 2, 2)
更改上下文的CTM(当前变换矩阵),则无需手动乘以坐标,您可以像非视网膜图像一样绘制相同的内容。 - epologeeCGFloat scale = [[UIScreen mainScreen] scale]; CGContextScaleCTM(UIGraphicsGetCurrentContext(), scale, scale);
。 - epologee