2013-05-13 76 views
0

如何獲取拍攝圖像的設備路徑? 我正在顯示圖像和下面我有切換時關閉我顯示項目的默認圖像,當我想顯示圖像哪個用戶捕獲。 在拍攝功能我可以設置圖像到我的ImageView如何找到路徑圖像,以便我可以重新加載後再次相同的圖像?

#pragma mark - UIImagePickerControllerDelegate 
- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [self dismissViewControllerAnimated:YES completion:NULL]; 
    NSLog(@"%@", info); 
    UIImage * imageTemp = [info objectForKey:UIImagePickerControllerEditedImage]; 

    if (imageTemp == nil) 
     imageTemp = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    [self.image setImage:imageTemp]; 
} 

,並設置圖像的ImageView,但我沒有路徑。我有打印信息,看起來像

{ 
    UIImagePickerControllerMediaMetadata =  { 
     DPIHeight = 72; 
     DPIWidth = 72; 
     Orientation = 6; 
     "{Exif}" =   { 
      ApertureValue = "2.526068811667588"; 
      BrightnessValue = "5.667090406070278"; 
      ColorSpace = 1; 
      DateTimeDigitized = "2013:05:14 01:02:48"; 
      DateTimeOriginal = "2013:05:14 01:02:48"; 
      ExposureMode = 0; 
      ExposureProgram = 2; 
      ExposureTime = "0.008620689655172414"; 
      FNumber = "2.4"; 
      Flash = 25; 
      FocalLenIn35mmFilm = 35; 
      FocalLength = "4.28"; 
      ISOSpeedRatings =    (
       50 
      ); 
      MeteringMode = 5; 
      PixelXDimension = 3264; 
      PixelYDimension = 2448; 
      SceneType = 1; 
      SensingMethod = 2; 
      ShutterSpeedValue = "6.862622389675391"; 
      SubjectArea =    (
       1631, 
       1223, 
       881, 
       881 
      ); 
      WhiteBalance = 0; 
     }; 
     "{TIFF}" =   { 
      DateTime = "2013:05:14 01:02:48"; 
      Make = Apple; 
      Model = "iPhone 4S"; 
      Software = "6.1.3"; 
      XResolution = 72; 
      YResolution = 72; 
     }; 
    }; 
    UIImagePickerControllerMediaType = "public.image"; 
    UIImagePickerControllerOriginalImage = "<UIImage: 0x20ac0470>"; 
} 

但我找不到任何我可以用來找到路徑。如何找到路徑圖像,以便以後可以重新載入相同的圖像?

+0

沒有圖像路徑。你所擁有的只是記憶中的圖像。除非將其保存到文件,否則沒有路徑。 – rmaddy 2013-05-13 23:09:09

回答

0

如果你想在你的應用程序的後期階段使用這個圖像,那麼你將不得不保存圖像的URL。

如果你想提取圖像的URL和圖像的名稱,你可以在它當前實施的委託方法它自己做。 NSDictionary信息包含有關圖像的所有信息。

#pragma mark - UIImagePickerControllerDelegate 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 

    NSURL *imagePath = [info objectForKey:@"UIImagePickerControllerReferenceURL"]; 
    NSString *imageName = [imagePath lastPathComponent]; 
} 

您可以在這個階段裏面保存didFinishPickingMediaWithInfo:

0

使用imagePath像我想你找不到路徑拍攝的圖像,因爲iPhone不救它,如果你從代碼中捕獲圖像文件。 在我看來,你有2種方法:

1)你可以創建一個單一類用於記憶變量中的UIImage,並且可以訪問它。

2)您可以將捕獲的圖像保存到緩存文件夾中的文件,然後獲取路徑;

相關問題