[英]Save image from UIWebView to camera roll with gesture
嗨我有点卡住保存图像,我已经构建了一个手势,并按照教程,但我有点卡住实际保存图像的最后部分。 非常感谢任何帮助。这是教程的来源
http://bees4honey.com/blog/tutorial/how-to-save-an-image-from-uiwebview/
提前致谢
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTouchesRequired = 2;
[self.myWebView addGestureRecognizer:doubleTap];
}
-(void) doubleTap :(UITapGestureRecognizer*) sender {
int scrollPositionY = [[self.myWebView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
int scrollPositionX = [[self.myWebView stringByEvaluatingJavaScriptFromString:@"window.pageXOffset"] intValue];
int displayWidth = [[self.myWebView stringByEvaluatingJavaScriptFromString:@"window.outerWidth"] intValue];
CGFloat scale = myWebView.frame.size.width / displayWidth;
CGPoint pt = [sender locationInView:self.myWebView];
pt.x *= scale;
pt.y *= scale;
pt.x += scrollPositionX;
pt.y += scrollPositionY;
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).tagName", pt.x, pt.y];
NSString * tagName = [self.myWebView stringByEvaluatingJavaScriptFromString:js];
NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", startPoint.x, startPoint.y];
NSString *urlToSave = [self.myWebView stringByEvaluatingJavaScriptFromString:imgURL];
/// Stuck at this point to actually get the file
}
NSURL *url = [NSURL URLWithString:urlToSave];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
UIImageWriteToSavedPhotosAlbum(image, <#id completionTarget#>, <#SEL completionSelector#>, <#void *contextInfo#>)
您可以将nil传递给所有三个参数。 所以你可以打电话
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.