Home > DeveloperSection > Forums > Converting web view contents into UIImage in iOS.
Anurag Sharma
Anurag Sharma

Total Post:40

Posted on    January-06-2016 4:27 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 530  View(s)
Rate this:
I have created a UIWebView in our iPhone application for displaying HTML formatted text. I want to animate web view on screen actually (2 to 10 times). and also my web views having transparent backgrounds.
after that web view is little heavy and although I haven't attempt it yet. I'm planning for the worst(I don't think it is premature optimization, I think it can be an issue).

I want to convert those contents of the web view into UIImages and using animation on it.
So, my problem is: How can I convert Web View contents into UIImage or CGImageRef? and Is transparency of web view be carried on to the UIImage?
Anyone have suggestions for my Issue, then please help me.

Tarun Kumar

Total Post:214

Posted on    January-07-2016 2:13 AM

Yes, you can create UIWebView into Images. below I am providing a solution:
UIGraphicsBeginImageContext (webViewController.bounds.size) ;
[webViewController.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
the above code will generate issue if your web views dimensions are bigger because the webview uses a CATiledLayer that doesn't draw everything, for memory reasons, and the transparent image can also include.

Don't want to miss updates? Please click the below button!

Follow MindStick