Tag: 核心graphics

有没有一个iOS的等效appendBezierPathWithArcWithCenter

我正在尝试在iOS中绘制四分之一圈。 在Mac OS中,似乎你可以使用appendBezierPathWithArcWithCenter,但这似乎不适用于iOS。 有谁知道如何简单地在iOS中画四分之一圈? 谢谢

CGAffineTransformMakeRotation在外部点附近

有没有办法使用CGAffineTranformMAkeRotation围绕外部点旋转UIImage? 很多!

如何使用Core Graphics(用于手指画)创build浮雕效果或阴影效果

我有问题在我的绘图中实现“浮雕/阴影效果”。 手指画图function目前正在我的自定义UIView工作正常,下面是我的drawRect方法代码: 用所有方法编辑代码: – (void)drawRect:(CGRect)rect { CGPoint mid1 = midPoint(previousPoint1, previousPoint2); CGPoint mid2 = midPoint(currentPoint, previousPoint1); CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; CGContextMoveToPoint(context, mid1.x, mid1.y); CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineWidth(context, self.lineWidth); CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); CGContextSaveGState(context); // for shadow effects CGContextSetShadowWithColor(context, CGSizeMake(0, 2),3, self.lineColor.CGColor); CGContextStrokePath(context); [super drawRect:rect]; } CGPoint midPoint(CGPoint p1, CGPoint p2) { […]

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

在我的iOS应用程序中,我正在尝试使用CoreGraphics绘制曲线。 绘图本身工作正常,但在视网膜显示图像绘制使用相同的分辨率,并没有得到像素加倍。 结果是一个像素化的图像。 我正在绘制使用以下function: – (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 […]

创build2个贝塞尔path的联合

我有两条贝塞尔path,我想组合起来组成一个联合体,这样我就可以抚摸整个外形。 就我而言,这是一个带有尾巴的语音气泡,虽然它不是一个复杂的形状,但是使用单一path创build它实际上是相当困难的。 似乎没有用于创build联合的Core Graphics API。 我错了吗? 如果我不是,有谁知道一个图书馆可以处理这个? 我searchGitHub无济于事。

核心graphics线条画和删除触摸

我正在写一个iPhone应用程序,有点像拿起appstore上的应用程序。 我已经完成了绘制多行并使用CoreGraphics显示它。 但是现在我遇到了如何在用户点击时删除这一行。 我在Google上search了很多,但没有find任何相关的信息。 我在其他地方见过你的这篇文章,这真的帮了我一个忙。 但问题是,如果我有一根棍子,然后在另一根棍子上。 当我点击下面的棍子,它不应该被删除,如果我点击上面的,它应该被删除,如果没有棍子上面。 如何实现这个事情..另外我需要存储的path,即我的行是UIBeizerpath在列表,数组,字典什么的,请帮助我这个东西也。 我没有find任何东西。

如何用渐变色填充贝塞尔path

我的自定义UIView draw(_ rect: CGRect)函数中有一个UIBezierPath 。 我想用渐变色填充path。 请任何人都可以指导我如何做到这一点。 我需要用渐变颜色填充剪辑,然后用黑色描边path。 SO中有一些post不能解决问题。 例如沿着bezierpath的Swift:Gradient(使用CALayers)这篇文章指导了如何在UIView绘制一个图层,但不是在UIBezierPath 。 注意:我正在Swift-3上工作

在UIScrollView中embeddedUIImage的自由绘图

我正在处理UIScrollView中的UIImage的徒手绘制项目。 一切工作正常与默认缩放绘图,但是,如果我调整UIScrollView的缩放,再次尝试绘图,它开始扭曲图像缩小,使图像看起来模糊。 它也将图像推到屏幕的最左侧。 我曾尝试使用不同的缩放选项无济于事。 这是正常的规模与一些graphics的图像。 这是缩放和绘图几秒后的图像 这里是相关的代码(方法在包含滚动视图的视图控制器中声明 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { super.touchesBegan(touches, with: event) } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { super.touchesMoved(touches, with: event) let currentPoint = touches.first!.location(in: drawingImageView) UIGraphicsBeginImageContextWithOptions(drawingImageView.frame.size, false, 0) drawingImageView.image?.draw(in: CGRect(x: 0, y: 0, width: drawingImageView.frame.size.width, height: drawingImageView.frame.size.height)) UIGraphicsGetCurrentContext()?.addRect(CGRect(x: currentPoint.x, y: currentPoint.y, width: 1, […]

使用Core Graphics绘制部分图像或对angular线剪切

我正在寻找使用Core Graphics绘制图像。然而,我能够绘制部分图像,即水平和垂直。 但是,而不是我想要在对angular线方式。更多的澄清,请参考下面的图像: 真实图像: 所需的图像输出: 以下是使用颜色填充图层的代码: CGContextRef contextRef = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(contextRef, r.origin.x, r.origin.y ); CGContextAddLineToPoint(contextRef, r.origin.x , r.origin.y); CGContextAddLineToPoint(contextRef, r.origin.x + (r.size.width ), r.origin.y + (r.size.height)); CGContextAddLineToPoint(contextRef, r.origin.x , r.origin.y + (r.size.height)); CGContextAddLineToPoint(contextRef, r.origin.x , r.origin.y); CGContextSetRGBFillColor(contextRef, [[color objectAtIndex:0]floatValue]/255.0f, [[color objectAtIndex:1]floatValue]/255.0f, [[color objectAtIndex:2]floatValue]/255.0f, .5); CGContextSetRGBStrokeColor(contextRef,[[color objectAtIndex:0]floatValue]/255.0f, [[color objectAtIndex:1]floatValue]/255.0f, [[color objectAtIndex:2]floatValue]/255.0f, 0.5); CGContextFillPath(contextRef); 现在,我想在这个graphics层上绘制一个图像,而不是填充颜色。我没有办法裁剪这个图像,因为我们只能传递像Origin x,y&Size Height,Width这样的参数。 […]

带有使用UIBezierPath的圆angular的多边形

我想使用UIBezierPath创build一个圆angular的多边形形状。 我相信这将可能使用addCurveToPoint:controlPoint1:controlPoint2:和类似的代码findhttp://www.codeproject.com/Articles/31859/Draw-a-Smooth-Curve-through-a-Set-of-二维点 – 机智 ,但我想知道是否有任何现有(或更好)的方式来实现这一目标? 我应该指出,这将需要为任何凸多边形(如在voronoi图中发现),而不是一个矩形的形状。