tags:

views:

240

answers:

3

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:

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.

Thank you all in advance

+1  A: 

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.

mahboudz
modifying alpha of that part of image is good idea but how can we modify alpha value of selected or touched part of image?do know how to do it?kindly help me.
milanjansari
Get the bitmap from the image or layer, see http://developer.apple.com/mac/library/qa/qa2007/qa1509.html, and then quickly run through the bitmap to find the touch point. Then play with the alpha values of the surrounding pixels.
mahboudz
Wait, there are probably better ways to do this like to draw another image on top with the appropriate blend mode to give you the alpha you need.
mahboudz
I wish stackoverflow was better at letting you know that someone had asked a question in a comment. I just happened to check back here. Two weeks later.
mahboudz
See CGContextClipToMask as one way of modifying alpha layers.
mahboudz
A: 

modifying alpha of that part of image is good idea but how can we modify alpha value of selected or touched part of image? do know how to do it? kindly help me.

milanjansari
A: 

anyone kindly help me above the question.

Thank you,

milanjansari