ios – 使用CoreGraphics绘制视网膜显示 – 图像像素化

ios – 使用CoreGraphics绘制视网膜显示 – 图像像素化,第1张

概述在我的iOS应用程序中,我试图用CoreGraphics绘制曲线.绘图本身工作正常,但在视网膜显示器上,图像使用相同的分辨率绘制,不会使像素倍增.结果是像素化图像. 我正在绘制使用以下功能: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [touches anyObje 在我的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,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}@H_419_5@  

我发现的建议是use the scaleFactor property,或CGContextSetShouldAntialias() function,但这两个都没有帮助到目前为止. (虽然我可能不正确地使用它们)

任何帮助将不胜感激.

解决方法 您需要用UIGraphicsBeginImageContext替换
if (UIGraphicsBeginImageContextWithOptions != NulL) {  UIGraphicsBeginImageContextWithOptions(size,NO,0.0);} else {  UIGraphicsBeginImageContext(size);}@H_419_5@  

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

总结

以上是内存溢出为你收集整理的ios – 使用CoreGraphics绘制视网膜显示 – 图像像素化全部内容,希望文章能够帮你解决ios – 使用CoreGraphics绘制视网膜显示 – 图像像素化所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1097668.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存