I'm sorry for not having a good format for the code, for they are copied from my blog.
It takes me a lot to edit.
1 To hide the part that you touch on.
When your finger moves, erase some parts :
- (UIImage *)erasePartsMoved {
UIImage *image = nil;
UIColor *color = [UIColor whiteColor];
CGFloat width = 5.0f;
CGSize imageContextSize = self.imageView.frame.size;
UIGraphicsBeginImageContext(imageContextSize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, width);
CGContextSetStrokeColorWithColor(context, [color CGColor]);
CGContextMoveToPoint(context, self.touchStartPoint.x, self.touchStartPoint.y);
//Do something needed.
CGContextAddLineToPoint(context, self.touchEndPoint.x, self.touchEndPoint.y);
CGContextStrokePath(context);
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;}
2 Your image is not visible at first, for example, transparent.
Get the point touched, then calculate a circle with the touched point, and finally change the alpha of the pixels in the circle:
typedef struct _singleRGBA{
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;} RGBA;
To change the pixel's alpha :
void filterOpacity(UInt8 *pixelBuf, UInt32 offset, void *context){
double val = *((double*)context);
int a = offset+3;
int alpha = pixelBuf[a];
pixelBuf[a] = SAFECOLOR(alpha * val);}
I hope the above would do a favor.
Funny question, I would like to do a runnable demo later.