【发布时间】:2011-01-21 07:59:39
【问题描述】:
使用 Monotouch,我如何在当前正在显示的 UIImage 中的图像上画一条简单的线?
简单的例子当然没问题。
Obj-C 答案也可以。
【问题讨论】:
标签: iphone uiimage xamarin.ios
使用 Monotouch,我如何在当前正在显示的 UIImage 中的图像上画一条简单的线?
简单的例子当然没问题。
Obj-C 答案也可以。
【问题讨论】:
标签: iphone uiimage xamarin.ios
假设您有一个自定义 UIImageView,并在其 Image 属性上设置了图像,请将此方法放入其中:
private void DrawLineOnImage()
{
UIGraphics.BeginImageContext(this.Image.Size);
using (CGContext cont = UIGraphics.GetCurrentContext())
{
cont.TranslateCTM(0f, this.Image.Size.Height);
cont.ScaleCTM(1.0f, -1.0f);
cont.DrawImage(new RectangleF(0f,0f,this.Image.Size.Width, this.Image.Size.Height), this.Image.CGImage);
cont.ScaleCTM(1.0f, -1.0f);
cont.TranslateCTM(0f, -this.Image.Size.Height);
using (CGPath path = new CGPath())
{
cont.SetLineWidth(3);
cont.SetRGBStrokeColor(255, 0, 0, 1);
path.AddLines(new PointF[] {
new PointF(10, 10),
new PointF(100, 100) });
path.CloseSubpath();
cont.AddPath(path);
cont.DrawPath(CGPathDrawingMode.FillStroke);
this.Image = UIGraphics.GetImageFromCurrentImageContext();
}//end using path
}//end using cont
UIGraphics.EndImageContext();
}//end void DrawLineOnImage
这会在图像本身上画一条红线。
【讨论】: