2009-09-05 105 views
1

我有兩個重疊的圖像。如果我刪除上面的圖像的一部分,該特定的部分被擦除並且底層圖像應該出現。但是,如果我把這個特定的部分弄清楚,它應該讓我回到那個圖像的被刪除部分。擦除和刪除圖像

我不需要撤消功能,但只有刪除的部分應該出現。

這裏是我使用擦除上面的圖像的代碼:

在touchesMoved事件:

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(); 

請幫我有關的問題。

謝謝大家提前

回答

1

而不刪除的,你爲什麼不修改阿爾法圖像的一部分。然後當你想要回來時,你可以修改alpha。

否則,當底部的圖像被擦除時,您應該恢復整個上部圖像。

+0

修改該部分圖像的alpha值是個好主意,但我們如何修改圖像的選定部分或觸摸部分的alpha值? 知道該怎麼做嗎? 請幫助我。 – milanjansari 2009-09-05 12:04:09

+0

從圖像或圖層獲取位圖,請參閱http://developer.apple.com/mac/library/qa/qa2007/qa1509.html,然後快速通過位圖運行以找到觸摸點。然後播放周圍像素的Alpha值。 – mahboudz 2009-09-23 08:51:41

+0

等一下,可能有更好的方法來做到這一點,就像用合適的混合模式在頂部繪製另一幅圖像,爲您提供所需的alpha。 – mahboudz 2009-09-23 08:52:48