Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在objective-c iPhone中缩放图像前后使用橡皮擦?_Iphone_Objective C_Image Processing_Erase - Fatal编程技术网

如何在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
    ,效果非常好。由于

    的原因,问题不在于移动或橡皮擦。问题是同时使用缩放和橡皮擦。你能提供解决方案吗?问题不在于机芯或橡皮擦。问题是同时使用缩放和橡皮擦。你能提供解决方案吗?