c# - 截取图像的一部分

标签 c# ios xamarin.ios xamarin

我想剪掉图像的一部分。 我的计划是创建一个带有图像的层,但图像溢出了层。

它应该看起来像这个例子:

the cutted image

有什么想法吗?谢谢。

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/

相关文章:

c# - 在 WPF 应用程序中全局设置文化 (en-IN)

javascript - 在 http Post 中传递对象数组

ios - 如何将这个 .plist 文件直接解析为 Swift 中的对象?

ios - map 在 Xamarin iOS 上的方向变化时失去位置

c# - Xamarin 代码生成设计器正在破坏应用程序

c# - 在 WinForms 的组合框中插入项目

c# - 如何在 Azure 中以辅助角色运行 RavenDb

ios - swift 3 - 推送通知的本地化不起作用

ios - 动态更改导航栏项目 - Swift

visual-studio - Xamarin.IOs 给出错误 "either upgrade Xcode or set the managed linker behaviour to Link Framework SDKs Only"