gpt4 book ai didi

iphone - 将 webview 中的照片保存到 ios 照片库

转载 作者:行者123 更新时间:2023-11-28 20:16:32 25 4
gpt4 key购买 nike

这是使用相机拍摄照片并保存在图库中的情况。并且照片在网页中打开以进行编辑以及如何使用其他名称保存回设备内存?即...如何将 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

截图

enter image description here

关于iphone - 将 webview 中的照片保存到 ios 照片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17855148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com