定位错误,我想问题在于错误
缩放比例
因为当我们使用图像时,图像的大小通常与
UIImageView
的大小。您使用图像的大小来绘制路径,因此它将丢失其位置。尝试这样修改:
if (null != touch)
{
UIGraphics.BeginImageContext(this.Frame.Size);
using (CoreGraphics.CGContext cont = UIGraphics.GetCurrentContext())
{
if (this.Image != null)
{
cont.TranslateCTM(0f, this.Frame.Size.Height);
cont.ScaleCTM(1.0f, -1.0f);
cont.DrawImage(new RectangleF(0f, 0f, Convert.ToSingle(this.Frame.Size.Width)
, Convert.ToSingle(this.Frame.Size.Height)), this.Image.CGImage);
cont.ScaleCTM(1.0f, -1.0f);
cont.TranslateCTM(0f, -this.Frame.Size.Height);
} //end if
CGPoint lastLocation = touch.PreviousLocationInView(this);
CGPoint pt = touch.LocationInView(this);
using (CGPath path = new CGPath())
{
cont.SetLineCap(CGLineCap.Round);
cont.SetLineWidth(10);
cont.SetStrokeColor(0, 2, 3, 1);
var xLoc = lastLocation.X;
var yLoc = lastLocation.Y;
path.MoveToPoint(xLoc, yLoc);
path.AddLines(new CGPoint[] { new CGPoint(xLoc,
yLoc),
new CGPoint(pt.X, pt.Y) });
path.CloseSubpath();
cont.AddPath(path);
cont.DrawPath(CGPathDrawingMode.FillStroke);
this.Image = UIGraphics.GetImageFromCurrentImageContext();
}//end using path
}//end using cont
UIGraphics.EndImageContext();
this.SetNeedsDisplay();
}//end if
关于
我必须用两个手指画画,但我只想用一个手指
手指
你这是什么意思?该代码只能用手指绘制路径。