我有一个应用程序,用户可以在加载的图像上自由绘制。他选择铅笔颜色,然后开始在图像上绘制。
除此之外,他可以使用手指将图像缩小和放大,这就是我遇到问题的地方。
缩放后,在图像上绘制时会变得模糊,并且奇怪地收缩...
缩放代码:
void ScaleImage (UIPinchGestureRecognizer gestureRecognizer)
{
AdjustAnchorPoint (gestureRecognizer);
if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) {
gestureRecognizer.View.Transform *= CGAffineTransform.MakeScale (gestureRecognizer.Scale, gestureRecognizer.Scale);
gestureRecognizer.Scale = 1;
}
}
绘图代码:
public override void TouchesBegan (NSSet touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
if (!canDraw)
return;
UITouch touch = (UITouch)touches.AnyObject;
lastPoint = touch.LocationInView (MyImageView);
}
public override void TouchesMoved (NSSet touches, UIEvent evt)
{
base.TouchesMoved (touches, evt);
if (!canDraw)
return;
UITouch touch = (UITouch)touches.AnyObject;
PointF currentPoint = touch.LocationInView (MyImageView);
UIGraphics.BeginImageContext (MyImageView.Frame.Size);
MyImageView.Image.Draw (new RectangleF (
0, 0,
MyImageView.Frame.Size.Width,
MyImageView.Frame.Size.Height));
CGContext ctx = UIGraphics.GetCurrentContext ();
ctx.SetLineCap (CGLineCap.Round);
ctx.SetLineWidth (5.0f);
ctx.SetRGBStrokeColor (red, green, blue, 1);
CGPath path = new CGPath ();
path.MoveToPoint(MyImageView.Transform, lastPoint.X, lastPoint.Y);
path.AddLineToPoint (MyImageView.Transform, currentPoint.X, currentPoint.Y);
ctx.AddPath (path);
ctx.DrawPath (CGPathDrawingMode.Stroke);
MyImageView.Image = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
lastPoint = currentPoint;
}
提前感谢您!
TouchesBegan
中的UIBezierPath
对象中包含以下属性来解决了这个问题:UIBezierPath path = new UIBezierPath { LineJoinStyle = CGLineJoin.Round, LineCapStyle = CGLineCap.Round };
- hvaughan3