在ios中将html转换为图像

时间:2022-04-22 08:59:10

I am using multiple .html files in my app and opens it in a webview , i need to show the html pages as a thumb view as well , is it possible to convert the html pages into images or any other methods to show the html files as a preview. Please help me if any one know

我在我的应用程序中使用多个.html文件并在webview中打开它,我需要将html页面显示为拇指视图,是否可以将html页面转换为图像或任何其他方法来显示html文件作为预览。如果有人知道,请帮助我

1 个解决方案

#1


1  

-(void) webViewDidFinishLoad:(UIWebView *)webView { 

UIGraphicsBeginImageContext(CGSizeMake(webView.layer.frame.size.width, webView.layer.frame.size.height));
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


UIGraphicsBeginImageContext(CGSizeMake(70,100));
[image drawInRect:CGRectMake(0, 0, 70,100)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//image is now a 70x100 thumbnail. make sure you include CoreGraphics
}

#1


1  

-(void) webViewDidFinishLoad:(UIWebView *)webView { 

UIGraphicsBeginImageContext(CGSizeMake(webView.layer.frame.size.width, webView.layer.frame.size.height));
[webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


UIGraphicsBeginImageContext(CGSizeMake(70,100));
[image drawInRect:CGRectMake(0, 0, 70,100)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//image is now a 70x100 thumbnail. make sure you include CoreGraphics
}