gpt4 book ai didi

iphone - Retina 中的 CGContextDrawImage 绘制像素化图像?

转载 作者:技术小花猫 更新时间:2023-10-29 10:40:59 24 4
gpt4 key购买 nike

我需要将图像绘制到 CALayer 中,因为我需要在其上执行各种效果、动画和滤镜。当我在 CGContext 中做简单的绘制时,无论我做什么,它总是被像素化......在视网膜上绘制上下文的正确方法是什么?

这就是我现在正在做的:

CGImageRef plateImage = [[UIImage imageNamed:@"someImage"] CGImage];
CGFloat width = CGImageGetWidth(plateImage), height = CGImageGetHeight(plateImage);
CGFloat scale = [[UIScreen mainScreen] scale];

NSLog(@"Scale: %f\nWidth: %f\nHeight: %f", scale, width, height);
CGContextTranslateCTM(_context, 0, height / scale);
CGContextScaleCTM(_context, 1.0, -1.0);

CGContextDrawImage(_context, CGRectMake(0, 0, width / scale, height / scale), plateImage);

最佳答案

我遇到了同样的问题,但解决方案似乎没有用。

UIGraphicsBeginImageContext() 结果导致了我的问题。我在这里为遇到同样问题的 future 用户发布我的解决方案。

从 iOS 4.0 开始你应该使用:

UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);

代替

UIGraphicsBeginImageContext(size);

如果您不想要像素化图像。

关于iphone - Retina 中的 CGContextDrawImage 绘制像素化图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9445875/

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