如何提取带有路径的 UIImage?
我需要将路径内的内容放入新的 UIImage 中。我需要的是旋转矩形的内容。这是我用来获取矩形角的代码。(x,y = 图像中心。图像的宽度、高度)。
UIBezierPath* aPath = [UIBezierPath bezierPath];
//1
[aPath moveToPoint:CGPointMake(
x+(width/2)*cosf(A)-(height/2)*sinf(A),
y+(height/2)*cosf(A)+(width/2)*sinf(A))];
NSLog(@"%f, %f", x+(width/2)*cosf(A)-(height/2)*sinf(A),
y+(height/2)*cosf(A)+(width/2)*sinf(A));
//2
[aPath moveToPoint:CGPointMake(
x-(width/2)*cosf(A)-(height/2)*sinf(A),
y+(height/2)*cosf(A)-(width/2)*sinf(A))];
NSLog(@"%f, %f", x-(width/2)*cosf(A)-(height/2)*sinf(A),
y+(height/2)*cosf(A)-(width/2)*sinf(A));
//3
[aPath moveToPoint:CGPointMake(
x-(width/2)*cosf(A)+(height/2)*sinf(A),
y-(height/2)*cosf(A)-(width/2)*sinf(A))];
NSLog(@"%f, %f", x-(width/2)*cosf(A)+(height/2)*sinf(A),
y-(height/2)*cosf(A)-(width/2)*sinf(A));
//4
[aPath moveToPoint:CGPointMake(
x+(width/2)*cosf(A)+(height/2)*sinf(A),
y-(height/2)*cosf(A)+(width/2)*sinf(A))];
NSLog(@"%f, %f", x+(width/2)*cosf(A)+(height/2)*sinf(A),
y-(height/2)*cosf(A)+(width/2)*sinf(A));
//5
[aPath moveToPoint:CGPointMake(
x+(width/2)*cosf(A)-(height/2)*sinf(A),
y+(height/2)*cosf(A)+(width/2)*sinf(A))];
NSLog(@"%f, %f", x+(width/2)*cosf(A)-(height/2)*sinf(A),
y+(height/2)*cosf(A)+(width/2)*sinf(A));
[aPath closePath];
我在想这样的事情:问题的图片。 (这里的形状不同。)我希望那个黄色部分是一个新的 UIImage。