我希望用URL加载Webview并获取内容(图像)。然后将其缩放以在小尺寸的WebView或Imageview中正确显示。
怎么做?
谢谢,
答案 0 :(得分:1)
在你的webView委托中尝试这样的事情:
- (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];
}
答案 1 :(得分:0)
在大多数情况下,你从UIView的CALayer中制作UIImage。有关详细信息,请参阅How to take an iPhone screenshot of entire view including parts off screen?。
然后您可以调整图像大小: