views:

38

answers:

1

Hi guy,

I want to create an UIImage of UIWebView and then I want to draw that image.

Here is my code:

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

but its not drawing anything other than a blank page. Cant we create UIImage like that or Am I doing something wrong somewhere in the code.

Thanx

+1  A: 

The next code should work:

UIGraphicsBeginImageContext(tempView.bounds.size);
[tempView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Michael Kessler
Thanx it is working now
Ideveloper