Capturing and storing a picture taken with the Camera into a local database / PhoneGap / Cordova / iOS

前端 未结 5 1006
走了就别回头了
走了就别回头了 2020-11-27 03:45

I\'m currently building an app for iOS using Phonegap/Cordova and jQuerymobile. The idea is to take photos with camera and store the captured image for future use. I would l

5条回答
  •  遥遥无期
    2020-11-27 04:18

    There are 3 steps:

    1. Get the photo. Apple has a good example for this on the iPhone dev site
    2. Get your Documents directory, like so:
      
      NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(
                  NSDocumentDirectory,
                  NSUserDomainMask,
                  YES);
      NSString *docDir = [arrayPaths objectAtIndex:0];
      
    3. And finally, storing the UIImage you got in step 1 out to disk:
      
      NSString *filename = @"mypic.png";
      NSString *fullpath = [docDir stringByAppendingPathComponent:filename];
      [UIImagePNGRepresentation(image) writeToFile:fullpath atomically:YES];
      

提交回复
热议问题