how to draw an image above an Transparent image using CoreGraphics
I want to daw an image on an transparent image using coreGraphics can any tell me with the 开发者_StackOverflowcouple of line of code?
- (void)drawRect:(CGRect)rect
{
UIImage *transparentImage = ...;
[trasparentImage drawInRect:rect]; ///< draw an trasparent image as background.
UIImage *anImage = ...;
[anImage drawInRect:rect]; ///< draw an image on an transparent image.
// get the result from current context
CGContextRef curCtx = UIGraphicsGetCurrentContext();
UIImage *result = UIGraphicsGetImageFromCurrentImageContext(curCtx);
....
}
One point: UIImage's draInRect will draw the image on the current context. In the UIView's -(void)drawRect:(CGRect)rect, it will push a context into stack. If you want to draw image in the method of self, you need to push a context as current context. Or, you have to create a context and draw the image by CGContextDrawImage() method.
精彩评论