删除和删除图像 [英] Erase and Unerase Image

查看:40
本文介绍了删除和删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个重叠的图像.如果我擦除了上面图像的一部分,则该特定部分将被擦除,并且下面的图像应该出现.但是,如果我删除该特定部分,它应该还给我该图像的已删除部分.

I am having two overlapping images. If I erase a portion of the above image, that specific portion gets erased and the underlying image should appear. But if I unerase that particular portion it should give me back the erased part of that image.

我不需要撤消功能,只应显示被擦除的部分.

I don't require undo functionality but only the erased portion should appear.

这是我用来删除上述图片的代码:

Here is the code which I am using to erase the above image:

在touchesMoved事件上:

On touchesMoved event:

UIGraphicsBeginImageContext(frontImage.frame.size);
[frontImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone); //kCGImageAlphaPremultipliedLast);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
//this line code for erasing select the part of the image
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 10, 10)); 
//End the code
CGContextStrokePath(UIGraphicsGetCurrentContext());
frontImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

请帮助我解决这个问题.

Kindly help me regarding the problem.

提前谢谢大家

推荐答案

为什么不删除图像,而不修改图像的该部分的alpha值.然后,当您需要它时,可以修改Alpha.

Instead of erasing, why don't you modify the alpha for that part of the image. Then when you want it back, you modify the alpha back.

否则,当底部的图像被删除时,您应该恢复整个上方的图像.

Otherwise you should restore the entire upper image when the bottom one is erased.

这篇关于删除和删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆