1

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,

TechFusion
  • 41
  • 1
  • 11

2 Answers2

1

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
  • 3,527
  • 1
  • 22
  • 12
  • 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 Jul 13 '10 at 06:27
  • 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 Jul 13 '10 at 18:58
0

In most cases, you make an UIImage out of a UIView's CALayer. See How to take an iPhone screenshot of entire view including parts off screen? for details.

You can then resize the image:

The simplest way to resize an UIImage?

Community
  • 1
  • 1
TechZen
  • 64,370
  • 15
  • 118
  • 145