我想剪掉图像的一部分。 我的计划是创建一个带有图像的层,但图像溢出了层。
它应该看起来像这个例子:
有什么想法吗?谢谢。
using (CGLayer starLayer = CGLayer.Create (g, rect.Size)) {
// set fill to blue
starLayer.Context.SetFillColor (0f, 0f, 1f, 0.4f);
starLayer.Context.AddLines (myStarPoints);
starLayer.Context.AddQuadCurveToPoint(this.points [3].X, this.points [3].Y, this.points [2].X, this.points [2].Y);
starLayer.Context.AddQuadCurveToPoint(this.points [5].X, this.points [5].Y, this.points [4].X, this.points [4].Y);
starLayer.Context.FillPath ();
double width = Math.Abs((double)(this.points [1].X - this.points [0].X));
float prop = this.tmpimage.Size.Width / (float)width;
float height = (this.tmpimage.Size.Height / prop);
double centerteeth = (Math.Sqrt (Math.Pow ((this.points [4].X - this.points [2].X), 2.0) + Math.Pow ((this.points [4].Y - this.points [2].Y), 2.0))) / 2 - (width/2);
starLayer.Context.DrawImage (new RectangleF ((float)centerteeth + this.points[2].X, this.points [2].Y, (float)width, height), this.imagerotated.CGImage);
// draw the layer onto our screen
float starYPos = 5;
float starXPos = 5;
g.DrawLayer (starLayer, new PointF (starXPos, starYPos));
}
最佳答案
如果您正在寻找一种快速解决方案来完成它,您可以使用两张图片来完成您的需要吗? (黑色图像,然后是背景)将一个 UIImageView
放在另一个之上?
我通常只使用 CoreGraphics
有两个原因:
- 没有其他方法可以实现我的目标
- 使用普通的
UIViews
性能不够
关于c# - 截取图像的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18466641/