如何在objective-c iPhone中缩放图像前后使用橡皮擦?
我正在做一些图像处理项目,我需要在图像上实现橡皮擦。我还必须实现收缩效果,以缩小或放大图像。掐的效果很好。橡皮擦也可以完美地工作,如果我不规模的图像捏。但当我用捏,然后用橡皮擦。图像变得模糊。我已经在如何在objective-c iPhone中缩放图像前后使用橡皮擦?,iphone,objective-c,image-processing,erase,Iphone,Objective C,Image Processing,Erase,我正在做一些图像处理项目,我需要在图像上实现橡皮擦。我还必须实现收缩效果,以缩小或放大图像。掐的效果很好。橡皮擦也可以完美地工作,如果我不规模的图像捏。但当我用捏,然后用橡皮擦。图像变得模糊。我已经在ui测试识别器上实现了橡皮擦 下面是橡皮擦的代码 CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender locationInView:tattooImage]; if([(UIPanGestureRecognizer*)sender s
ui测试识别器
上实现了橡皮擦
下面是橡皮擦的代码
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender locationInView:tattooImage];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
{
lastPoint = translatedPoint;
//lastPoint.x += 60;
//lastPoint.y += 60;
}
else
{
CGPoint currentPoint = translatedPoint;
//currentPoint.x += 60;
//currentPoint.y += 60;
UIGraphicsBeginImageContext(tattooImage.frame.size);
[tattooImage.image drawInRect:CGRectMake(0, 0,tattooImage.frame.size.width, tattooImage.frame.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext( ),kCGBlendModeClear);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 25.0);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor clearColor] CGColor]);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
tattooImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
请提供任何帮助。提前谢谢。我想我有一个解决办法。首先,您要使用
ui搜索识别器
移动对象。您可以简单地告诉我们UITouch
,因为实现起来会更容易。我提供了一些代码:-
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = YES;
UITouch *touch = [[event touchesForView:imageView] anyObject];
CGPoint currentPoint = [touch locationInView:drawingView];
UIGraphicsBeginImageContext(drawingView.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, drawingView.frame.size.width, drawingView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 5.0);
if (eraserSelected)
{
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 10.0);
}
[self changeBrushColor];
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext() , lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
现在,您可以创建自己的
触摸开始
和触摸结束
方法。我想我有一个解决方案。首先,您要使用ui搜索识别器
移动对象。您可以简单地告诉我们UITouch
,因为实现起来会更容易。我提供了一些代码:-
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = YES;
UITouch *touch = [[event touchesForView:imageView] anyObject];
CGPoint currentPoint = [touch locationInView:drawingView];
UIGraphicsBeginImageContext(drawingView.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, drawingView.frame.size.width, drawingView.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 5.0);
if (eraserSelected)
{
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
CGContextSetLineWidth(UIGraphicsGetCurrentContext( ), 10.0);
}
[self changeBrushColor];
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext() , lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext()) ;
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
现在,您可以创建自己的
触摸开始
和触摸结束
方法。图像处理程序的工作方式不是直接处理屏幕上显示的内容(除了MSPaint…),而是将所有工作应用于1:1比例的副本,并向您显示该副本的放大版本
您需要做的是将正在处理的图像保存在屏幕外。屏幕上显示的图像需要从此源复制
然后,您可以计算与图像相关的所有触摸事件发生的位置,而不是将擦除/绘制直接应用于屏幕上的图像,而是将它们应用于适当缩放的未缩放图像
大致如下:
图像处理程序的工作方式不是直接处理屏幕上显示的内容(除了MSPaint…),而是将所有工作应用于1:1比例的副本,并向您显示该副本的放大版本 您需要做的是将正在处理的图像保存在屏幕外。屏幕上显示的图像需要从此源复制 然后,您可以计算与图像相关的所有触摸事件发生的位置,而不是将擦除/绘制直接应用于屏幕上的图像,而是将它们应用于适当缩放的未缩放图像 大致如下:
我找到了解决办法。我做了一个小小的改变,我得到了想要的结果。我用
纹身图像.bounds.size
更改了代码中的纹身图像.frame.size
,效果非常好。多亏了我找到了解决办法。我做了一个小小的改变,我得到了想要的结果。我用纹身图像.bounds.size
更改了代码中的纹身图像.frame.size
,效果非常好。由于的原因,问题不在于移动或橡皮擦。问题是同时使用缩放和橡皮擦。你能提供解决方案吗?问题不在于机芯或橡皮擦。问题是同时使用缩放和橡皮擦。你能提供解决方案吗?