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

时间:2013-07-25 10:15:18

标签: iphone ios ios-camera

这是使用相机拍摄照片并保存在库中的情况。 并且在网页中打开照片以进行编辑以及如何使用其他名称保存回设备内存?即......如何将webview中显示的照片保存到照片库? 谢谢你。

2 个答案:

答案 0 :(得分:3)

波纹管方法完成了您的需求: -

 - (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 gose到this

<强>截图

enter image description here

答案 1 :(得分:0)

here阅读教程。它将解决您的问题