2010-07-01 53 views
1

我想创建一个UIWebView的UIImage,然后我想绘制该图像。创建UIView图像的问题

这里是我的代码:

UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)]; 
tempView.backgroundColor = [UIColor blueColor]; 

UIGraphicsBeginImageContext(tempView.bounds.size); 
    [tempView drawRect:tempView.bounds]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height); 
CGContextDrawImage(ctx, imageRect, [image CGImage]); 

,但它不是画比一个空白页面的任何其他。不能我们创建这样的UIImage,或者我在代码中的某处做了什么错误。

感谢名单

回答

4

下面的代码应该工作:

UIGraphicsBeginImageContext(tempView.bounds.size); 
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
+0

感谢名单现在是工作 – Ideveloper 2010-07-01 12:06:25