gpt4 book ai didi

ios - 在 Cglayer 中绘制时模糊描边

转载 作者:行者123 更新时间:2023-11-28 20:08:53 25 4
gpt4 key购买 nike

我正在使用一个绘图应用程序,我在 CGlayers 中绘图,然后在图形上下文中绘图,但我的绘图变得模糊。

这是我的代码

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();//Get a reference to current context(The context to draw)
NSLog(@"Size1%@", NSStringFromCGRect(self.bounds));

if(self.currentDrawingLayer == nil)
{
self.currentDrawingLayer = CGLayerCreateWithContext(context, self.bounds.size, NULL);
}


CGPoint mid1 = midPoint(m_previousPoint1, m_previousPoint2);
CGPoint mid2 = midPoint(m_currentPoint, m_previousPoint1);


CGContextRef layerContext = CGLayerGetContext(self.currentDrawingLayer);
// UIGraphicsBeginImageContextWithOptions(self.bounds.size,YES,0.0);

CGContextSetLineCap(layerContext, kCGLineCapRound);
CGContextSetBlendMode(layerContext, kCGBlendModeNormal);
CGContextSetLineJoin(layerContext, kCGLineJoinRound);
CGContextSetLineWidth(layerContext, self.lineWidth);
CGContextSetStrokeColorWithColor(layerContext, self.lineColor.CGColor);
CGContextSetShouldAntialias(layerContext, YES);
CGContextSetAllowsAntialiasing(layerContext, YES);
CGContextSetAlpha(layerContext, self.lineAlpha);
CGContextSetFlatness(layerContext, 1.0f);
CGContextBeginPath(layerContext);
CGContextMoveToPoint(layerContext, mid1.x, mid1.y);//Position the current point
CGContextAddQuadCurveToPoint(layerContext, m_previousPoint1.x, m_previousPoint1.y, mid2.x, mid2.y);
CGContextStrokePath(layerContext);//paints(fills) the line along the current path.

CGContextDrawLayerInRect(context, self.bounds, self.currentDrawingLayer);
}

根据文档,每当我们使用 graphicsContext 创建 CGlayer 时,我都会用这段代码得到模糊的笔画,他们说它将提供设备的分辨率,但为什么我会得到模糊的线条。

这是模糊线的图像 enter image description here

问候兰 git

最佳答案

在您创建 CGLayer 的代码中替换它:

if(self.currentDrawingLayer == nil)
{
CGFloat scale = self.contentScaleFactor;
CGRect bounds = CGRectMake(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale);
CGLayerRef layer = CGLayerCreateWithContext(context, bounds.size, NULL);
CGContextRef layerContext = CGLayerGetContext(layer);
CGContextScaleCTM(layerContext, scale, scale);
self.currentDrawingLayer = layer;
}

关于ios - 在 Cglayer 中绘制时模糊描边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21028014/

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