CONVERTING WEB VIEW CONTENTS INTO UIIMAGE IN IOS.

Anurag Sharma

Total Post:40

Points:280
Posted by  Anurag Sharma
 576  View(s)
Ratings:
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.
  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Converting web view contents into UIImage in iOS.

    Yes, you can create UIWebView into Images. below I am providing a solution:

    UIGraphicsBeginImageContext (webViewController.bounds.size) ;
    [webViewController.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!