gpt4 book ai didi

ios - 使用手势将图像从 UIWebView 保存到相机胶卷

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:20 26 4
gpt4 key购买 nike

您好,我在保存图像时遇到了一些困难,我构建了一个手势并按照教程进行操作,但在实际保存图像的最后部分遇到了一些困难。任何帮助将不胜感激这里是教程源码

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);

关于ios - 使用手势将图像从 UIWebView 保存到相机胶卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13771814/

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