如何在iOS中获取保存的图像文件路径

问题描述:

您好我正在开发一个应用程序,其中有一个选项可以从iOS照片库中选择照片。我必须将选定的照片上传到服务器。要上传我使用的图像Kaltura SDK所以我在这种情况下不能直接发送UIImage到服务器。我需要发送保存的图像文件路径如何在iOS中获取保存的图像文件路径

为此我找到了解决方案,即将选定的照片保存在特定的文件路径中,然后我将使用该文件路径。但问题是我不希望将照片再次保存在手机内存中,因为这些照片已经存储在特定路径中。

所以有没有其他选项来检索保存的图像文件路径而不再保存它?

试试这个:

- (void)saveImage: (UIImage*)image 
{ 
    if (image != nil) 
    { 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                 NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
     NSString* path = [documentsDirectory stringByAppendingPathComponent: 
         @"test.png" ]; 
     NSData* data = UIImagePNGRepresentation(image); 
     [data writeToFile:path atomically:YES]; 
    } 
} 

- (UIImage*)loadImage 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString* path = [documentsDirectory stringByAppendingPathComponent: 
        @"test.png" ]; 
    UIImage* image = [UIImage imageWithContentsOfFile:path]; 
    [self sendAction:path]; 
    return image; 
} 
+0

感谢响应这是我目前完成的,在这里我们再次存储在一个特定的文件路径的图像,我的问题是没有任何选项来获得的路径,而不是存储它 – thavasidurai 2013-04-25 14:07:22

+0

是否有一个选项可以在将它发送到服务器后删除该路径? – thavasidurai 2013-04-25 14:10:49

+0

@Mutawe:你能告诉我如何从相同的路径删除图像? for this +1 – python 2013-07-12 10:37:40