【问题标题】:How to get the full file path of an UIImage [duplicate]如何获取 UIImage 的完整文件路径 [重复]
【发布时间】:2015-07-21 20:57:22
【问题描述】:

我有一个 UI 图像,我想找到它的路径。我该怎么做呢?

UIIImage *image ; // I have saved an image here
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; 

NSString *filePath = [documentsPath stringByAppendingPathComponent: ????????? ]; // How to get the image from UIImage ?

【问题讨论】:

  • 图片如何保存?为什么不知道保存在哪里?
  • 保存在相册中

标签: ios objective-c


【解决方案1】:

我告诉你问题的解决方案

  STEP 1: If you have the image in Bundle,just follow the below code

      NSString *stringImagePath = [[NSBundle mainBundle] pathForResource:@"Your_Image_Name" ofType:@"jpg"]; // or ofType:@"png", etc. 

  STEP 2: If you have image in particular place,just do the following code

     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
     NSString *documentsDirectory = [paths objectAtIndex:0];
     NSString* path = [documentsDirectory stringByAppendingPathComponent:
                  @"yourimage.png" ]; //or yourimage.jpg
     NSLog(@"The image path is-%@",path);
     NSData* data = UIImagePNGRepresentation(image);
     [data writeToFile:path atomically:YES]; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多