-1

Hi,

I'm planning to do an app that saves images to app documents folder but I don't know where to start.

My plan is whenever the method

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image 
                  editingInfo:(NSDictionary *)editingInfo

is called I'll save the UIImage to Apps Directory(Own Folder based on Image Category) and then retrieve it via UICollectionView.

I hope you can help me.. thanks :D

Evan
  • 750
  • 7
  • 13
Ron Pelayo
  • 655
  • 2
  • 7
  • 22

1 Answers1

0

Using this:

http://blog.objectgraph.com/index.php/2010/04/05/download-an-image-and-save-it-as-png-or-jpeg-in-iphone-sdk/

NSLog(@"%f,%f",image.size.width,image.size.height);

    // Let's save the file into Document folder.
    // You can also change this to your desktop for testing. (e.g. /Users/kiichi/Desktop/)
    // NSString *deskTopDir = @"/Users/kiichi/Desktop";

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

    // If you go to the folder below, you will find those pictures
    NSLog(@"%@",docDir);

    NSLog(@"saving png");
    NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir];
    NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
    [data1 writeToFile:pngFilePath atomically:YES];

    NSLog(@"saving jpeg");
    NSString *jpegFilePath = [NSString stringWithFormat:@"%@/test.jpeg",docDir];
    NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];//1.0f = 100% quality
    [data2 writeToFile:jpegFilePath atomically:YES];

    NSLog(@"saving image done");
Sam Jarman
  • 7,277
  • 15
  • 55
  • 100