Hello,
I am looking to load Webview with URL and get content(images) of that.Then scale it to display properly in small size of WebView ot Imageview.
How to do that ?
Thanks,
Hello,
I am looking to load Webview with URL and get content(images) of that.Then scale it to display properly in small size of WebView ot Imageview.
How to do that ?
Thanks,
You make an UIImage out of the UIWebview's CGLayer. See http://stackoverflow.com/questions/2328201/how-to-take-an-iphone-screenshot-of-entire-view-including-parts-off-screen for details.
You can then resize the image.
http://stackoverflow.com/questions/2658738/the-simplest-way-to-resize-an-uiimage/2658960#2658960
Try something like this in your webView delegate:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
CGSize thumbsize = CGSizeMake(100,100);
UIGraphicsBeginImageContext(thumbsize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGFloat scalingFactor = thumbsize.width/webView.frame.size.width;
CGContextScaleCTM(context, scalingFactor,scalingFactor);
[webView.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *thumbImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//throw it on screen, just for testing
UIImageView *imgView = [[[UIImageView alloc] initWithImage:thumbImage] autorelease];
[self.view addSubview:imgView];
}