gpt4 book ai didi

ios - 使用 CoreGraphics 在视网膜显示器上绘图 - 图像像素化

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

在我的 iOS 应用程序中,我尝试使用 CoreGraphics 绘制曲线。绘图本身工作正常,但在视网膜显示器上,图像使用相同的分辨率绘制,并且像素没有加倍。结果是像素化图像。

我正在使用以下函数绘图:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.canvasView];

UIGraphicsBeginImageContext(self.canvasView.frame.size);
[canvasView.image drawInRect:self.canvasView.frame];
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(ctx, YES);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, 5.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(ctx, currentPoint.x, currentPoint.y);
CGContextStrokePath(ctx);
canvasView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

lastPoint = currentPoint;
// some code omitted from this example
}

我找到的建议是 use the scaleFactor property ,或 CGContextSetShouldAntialias() function ,但到目前为止,这些都没有帮助。 (虽然我可能使用不当。)

如有任何帮助,我们将不胜感激。

最佳答案

您需要将 UIGraphicsBeginImageContext 替换为

if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
} else {
UIGraphicsBeginImageContext(size);
}

UIGraphicsBeginImageContextWithOptions 是在 4.x 软件中引入的。如果你打算在 3.x 设备上运行这段代码,你需要弱链接 UIKit 框架。如果您的部署目标是 4.x 或更高版本,您可以只使用 UIGraphicsBeginImageContextWithOptions 而无需任何额外检查。

关于ios - 使用 CoreGraphics 在视网膜显示器上绘图 - 图像像素化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6965873/

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