Save image captured by Camera into Documents Directory in ios

12,654

Try

UIImage *image = [UIImage imageNamed:@"Image.jpg"];
NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"New Folder"];
// New Folder is your folder name
NSError *error = nil;
if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error];

NSString *fileName = [stringPath stringByAppendingFormat:@"/image.jpg"];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
[data writeToFile:fileName atomically:YES];
Share:
12,654
Parimala
Author by

Parimala

Updated on July 02, 2022

Comments

  • Parimala
    Parimala almost 2 years

    Hi I am new to iPhone Environment. I am using the Xcode 4.5. I am developing the Camera Application now. I want to save the image is taking from the Camera to a Separate folder in Documents Directory and also in a Custom album in Photo Library .. I am saving the images to Custom album in Photo Library but I don't know how to save it to Documents Directory... Can anyone tell me how to do this..?

  • Parimala
    Parimala about 11 years
    Thanks for your response..I tried this code its working but Where Do I have to seen that image to check the image size..?
  • Girish
    Girish about 11 years
    Try following path : Finder -> Go -> Go to Folder -> /Users/GirishS/Library/Application Support/iPhone Simulator. Replace GirishS with your system name.
  • Parimala
    Parimala about 11 years
    In Application Support it is not showing the iPhone Simulator..!
  • Girish
    Girish about 11 years
    - Execute the following command on terminal to unhide the hidden folders. chflags nohidden ~/library/
  • Parimala
    Parimala about 11 years
    iPhone Simulator is not showing after executing the above command..
  • Girish
    Girish about 11 years
    Still iPhone simulator is showing or not....
  • Girish
    Girish about 11 years
    It works for me, don't know why not worked for you? try following link stackoverflow.com/questions/8738019/…