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

标签 iphone ios ios-camera

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

相关文章:

iphone - UIViewController 从 View 堆栈中弹出,NSURLConnection 使应用程序崩溃

iphone - IOS 应用程序被拒绝 : 2. 23 - 应用程序必须遵循 iOS 数据存储指南

ios - 使用自动布局创建 UIButton 时,如何删除 UIButton 的顶部和底部填充?

iOS 相机通过浏览器访问。覆盖?

ios - 如何强制 iOS 相机使用 AVFoundation 以编程方式拍照?

ios - 相机直接到 iOS 上的 OpenGL 纹理

iphone - 是否有一种全局方法可以将 iPhone 和 iPad 应用程序合并为通用应用程序?

iphone - 即使页面稍后加载,也会使用 UIWebView 调用 didFailLoadWithError

ios - 类型 'inout UIButton' 不符合协议(protocol) 'ReactiveCompatible'

ios - 如何使用 AFNetworking 传递数组值?