Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 创建UIView图像时遇到的问题_Iphone_Uiview_Uiimage - Fatal编程技术网

Iphone 创建UIView图像时遇到的问题

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

我想创建UIWebView的UIImage,然后我想绘制该图像

这是我的密码:

    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();