0

我有一个UIWebView. 将数据加载到 UIWebView 后,我UIWebView可以水平滚动,并在 Web 视图中为我的 scrollView 启用分页。

我的问题是:

有什么方法可以将 UIWebView 中 scrollView 中的页面保存到图像中?我的意思是,我会为 5 页滚动视图(内容大小 = 5 页)获得 5 张图像

4

3 回答 3

0

您可以像这样保存屏幕:-

 -(IBAction)savebutn:(id)sender
 {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(saveImage);
NSFileManager *fileMan = [NSFileManager defaultManager];

NSString *fileName = [NSString stringWithFormat:@"%d.png",imagename];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
[fileMan createFileAtPath:pdfFileName contents:imageData attributes:nil];


 }

您的图片将以 .png 扩展名保存在您的文档目录中

于 2012-10-08T09:29:04.177 回答
0

当用户想要捕获当前视图 ScreenShot 并共享或保存此图像时,此代码很有用....

- (UIImage *)captureView {

//hide controls if needed
CGRect rect = [self.view bounds];

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self.view.layer renderInContext:context];   
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;

}

看我的博客,... http://parasjoshi3.blogspot.in/2012/06/captureimagescreenshot-of-view.html

:)

于 2012-10-08T09:30:33.223 回答
0
CGRect rect = [webview bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[webview.layer renderInContext:context];   
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

这有助于捕获当前图像

于 2012-10-08T09:33:02.490 回答