本文介绍了从另一个路径的线宽轮廓生成CGPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能不会以最好的方式来解释这一点,所以请您忍受。

I might not be explaining this in the best way possible, so please bear with me.

我所拥有的是在MKMapView对象顶部绘制的CGPath:

What I have is a drawn CGPath on top of a MKMapView object:

我能够实现此目的的方法是为较深的蓝线创建CGPath,然后创建该路径的副本,然后使用半透明的蓝色描出该路径的较粗版本。这是我目前正在使用的代码:

The way I was able to achieve this is to create a CGPath for the darker blue line, then create a copy of that path, and then stroke a thicker version of it with a semi-transparent blue color. Here's the code that I'm currently using for this:

    // set the shadow around the path line
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGContextSetRGBStrokeColor(context, 0.0f, 0.0f, 0.0f, 0.0f);
    CGContextSetRGBFillColor(context, 0.0f, 0.0f, 1.0f, 0.4f);
    CGPathRef shadowPath = CGPathCreateCopyByStrokingPath(self.path.CGPath, NULL, 80.0f, kCGLineCapRound, kCGLineJoinRound, 0.0f);
    CGContextBeginPath(context);
    CGContextAddPath(context, shadowPath);
    CGContextDrawPath(context, kCGPathFillStroke);
    CGContextRestoreGState(context);
    CGPathRelease(shadowPath);

效果很好,到目前为止没有错。

Works pretty well, nothing wrong so far.

但是,我想做的是获取一个较粗的半透明蓝色区域的轮廓的CGPathRef。这是另一个截图,显示了我想要的伪路径(用红色绘制):

However, what I would like to do though is to get a CGPathRef of the outline of that thicker semi-transparent blue area. Here's another screenshot showing the pseudo-path that I want out of this (hand drawn in red):

这怎么可能?

推荐答案

简单:只需使用。传递宽线宽,并且上限为 kCGLineCapRound

这篇关于从另一个路径的线宽轮廓生成CGPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 21:24