Iphone 如何使用CoreGraphics在透明图像上方绘制图像

Iphone 如何使用CoreGraphics在透明图像上方绘制图像,iphone,Iphone,我想使用coreGraphics在透明图像上绘制一幅图像,用几行代码可以告诉我吗?-(void)drawRect:(CGRect)rect - (void)drawRect:(CGRect)rect { UIImage *transparentImage = ...; [trasparentImage drawInRect:rect]; ///< draw an trasparent image as background. UIImage *anImage = ...

我想使用coreGraphics在透明图像上绘制一幅图像,用几行代码可以告诉我吗?

-(void)drawRect:(CGRect)rect
- (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);

   ....
}
{ UIImage*透明图像=。。。; [trasparentImage drawInRect:rect];//<绘制一个trasparentImage作为背景。 UIImage*anImage=。。。; [anImage drawInRect:rect];//<在透明图像上绘制图像。 //从当前上下文中获取结果 CGContextRef curCtx=UIGraphicsGetCurrentContext(); UIImage*result=UIGraphicsGetImageFromCurrentImageContext(curCtx); .... }

一点:UIImage的draInRect将在当前上下文中绘制图像。在UIView的-(void)drawRect:(CGRect)rect中,它将上下文推送到堆栈中。如果您想用self方法绘制图像,则需要将上下文推送到当前上下文。或者,你必须创建一个上下文并通过CGContextDrawImage()方法绘制图像。

我试了很多次,但效果不好,我会给你看一些框架…根据这个框架,我必须设置图像。/Users/priyankmaheshwari/Desktop/Screen shot 2010-12-14下午3:00.44。pngI不知道你尝试了什么。你能提供你尝试过的代码吗?我说,如果你想用自己的方法画图像,你需要把一个上下文作为当前上下文。