【问题标题】:Problem in creating image of UIViewUIView 创建图片的问题
【发布时间】:2010-07-01 11:41:49
【问题描述】:

我想创建 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 还是我在代码的某个地方做错了什么。

感谢

【问题讨论】:

    标签: iphone uiview uiimage


    【解决方案1】:

    下一个代码应该可以工作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多