2013-07-25 142 views
0

這是使用照相機拍攝並保存在庫中的照片。 並且該照片在網頁中打開以進行編輯以及如何使用其他名稱保存到設備內存中? ie ... Hw將webview中顯示的照片保存到照片庫? 謝謝你。將webview中的照片保存到ios照片庫

+0

是的,我已經做了,你說什麼,我的疑問句是從那以後,我已經修改了照片中的WebView那麼如何保存迴文檔目錄或照片庫相同或區分的名稱 –

+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

+0

謝謝它的工作... NSString * imgURL = [NSString stringWithFormat:@「document.elementFromPoint(%f,%f).src」,touchPoint.x,touchPoint.y]; NSString * urlToSave = [webV stringByEvaluatingJavaScriptFromString:imgURL];這裏它使用的手勢權利?如果我們通過圖像標籤ID得到imgURL,那會更好。 –

+0

不用標籤測試,你必須用標籤測試它.. :) –

0

here閱讀教程。這將解決您的問題