这是使用相机拍摄照片并保存在图库中的情况。 并且照片在网页中打开以进行编辑以及如何使用其他名称保存回设备内存?即...如何将 webview 中显示的照片保存到照片库? 提前致谢。
最佳答案
以下方法满足您的需要:-
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *url = [NSURL URLWithString:@"yourimageurl"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webV loadRequest:req];
UITapGestureRecognizer *gs = [[UITapGestureRecognizer alloc] init];
gs.numberOfTapsRequired = 1;
gs.delegate = self;
[self.view addGestureRecognizer:gs];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
NSLog(@"TAPPED");
//Touch gestures below top bar should not make the page turn.
//EDITED Check for only Tap here instead.
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
CGPoint touchPoint = [touch locationInView:self.view];
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
bool pageFlag = [userDefaults boolForKey:@"pageDirectionRTLFlag"];
NSLog(@"pageFlag tapbtnRight %d", pageFlag);
if(self.interfaceOrientation==UIInterfaceOrientationPortrait||self.interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", touchPoint.x, touchPoint.y];
NSString *urlToSave = [webV stringByEvaluatingJavaScriptFromString:imgURL];
NSLog(@"urlToSave :%@",urlToSave);
NSURL * imageURL = [NSURL URLWithString:urlToSave];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];
imgView.image = image;
}
}
return YES;
}
下载演示:
http://dl.dropbox.com/u/51367042/ImageFromWebView.zip和 cradit 转到 this
截图
关于iphone - 将 webview 中的照片保存到 ios 照片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17855148/