views:

163

answers:

1

i want to track finger touch and draw the path on top of the imageView. following is what i did:

In the touch event:

UIgraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:CGRectMake(0,0,imageView.size.width,imageView.size.height)];

//drawing.....
imageView.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

however, the drawing opaque the background Image? how to drawing the path while still can make the background available?

thanks in advance:)

A: 

If you're doing simple vector drawing, you can set a color with a non-1.0 alpha value. These shapes will then be translucent when you draw them on top of your image. For example:

CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGFloat values[4] = {1.0, 0.0, 0.0, 0.5}; 
CGColorRef translucentRed = CGColorCreate(space, values); 

CGContextSetStrokeColorWithColor(context, translucentRed);
CGContextSetFillColorWithColor(context, translucentRed)

// Do your drawing here

CGColorRelease(translucentRed);
CGColorSpaceRelease(space);

will create a translucent red color and set the current stroke and fill to use that color.

Note that overlapping drawn elements will have darker areas because of this translucency, which might be an effect that you don't want.

Brad Larson