Iphone 创建UIView图像时遇到的问题
我想创建UIWebView的UIImage,然后我想绘制该图像 这是我的密码:Iphone 创建UIView图像时遇到的问题,iphone,uiview,uiimage,Iphone,Uiview,Uiimage,我想创建UIWebView的UIImage,然后我想绘制该图像 这是我的密码: UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)]; tempView.backgroundColor = [UIColor blueColor]; UIGraphicsBeginImageContext(tempView.bounds.size); [tempView drawRect:te
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,或者我在代码中的某个地方做错了什么
Thanx下一个代码应该可以工作:
UIGraphicsBeginImageContext(tempView.bounds.size);
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
下一个代码应该可以工作:
UIGraphicsBeginImageContext(tempView.bounds.size);
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();