【问题标题】:Where should I store an image selected on the iPhone?我应该在哪里存储在 iPhone 上选择的图像?
【发布时间】:2009-03-18 14:41:10
【问题描述】:

我想拍照或从用户现有照片中选择现有照片。做这个的最好方式是什么?

我特别关心我应该在哪里存储图像。存储位置应该是应用程序私有的。每次应用程序打开时,我都需要能够重用图像作为背景。谢谢!

【问题讨论】:

    标签: iphone objective-c cocoa-touch


    【解决方案1】:

    您应该使用 UIImagePickerController 从库或相机中检索图像。您可以将图片保存在 App 的 Documents 文件夹中。此文件夹对您的应用程序是私有的并且是可写的。

    【讨论】:

      【解决方案2】:

      您可以像这样获取文档文件夹的路径

      NSArray *sysPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
      NSString *docDirectory = [sysPaths objectAtIndex:0];
      

      并在那里保存一个文件。

      NSString *filePath = [NSString stringWithFormat:@"%@whatever.jpg",docDirectory];
      NSData *toSave = UIImageJPEGRepresentation(image,1.0); //image is a UIImage
      [toSave writeToFile:filePath atomically:YES]; 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-03-09
        • 2018-06-09
        • 2023-04-07
        • 1970-01-01
        • 2019-04-25
        • 2013-12-15
        • 1970-01-01
        相关资源
        最近更新 更多