views:

98

answers:

2

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,

+1  A: 

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];
}
joshrl
Thanks, for giving reply.In My application WebView continuously getting images from backend server, So it won't got in -WebViewDidFinishLoad method. Like continuously getting images from Webcamera.Do you have any idea how to do in that case ?
TechFusion
You might try something with the UIWebView method stringByEvaluatingJavaScriptFromString which I haven't used but presumable would allow you to call some javascript on the web page that checks if an image is loaded.
joshrl