1

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
  • 131
  • 1
  • 2
  • 12

1 Answers1

13

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];
Girish
  • 4,692
  • 4
  • 35
  • 55
  • Thanks for your response..I tried this code its working but Where Do I have to seen that image to check the image size..? – Parimala Feb 25 '13 at 10:20
  • Try following path : Finder -> Go -> Go to Folder -> /Users/GirishS/Library/Application Support/iPhone Simulator. Replace GirishS with your system name. – Girish Feb 25 '13 at 10:26
  • In Application Support it is not showing the iPhone Simulator..! – Parimala Feb 25 '13 at 10:46
  • - Execute the following command on terminal to unhide the hidden folders. chflags nohidden ~/library/ – Girish Feb 25 '13 at 10:48
  • iPhone Simulator is not showing after executing the above command.. – Parimala Feb 25 '13 at 11:47
  • Still iPhone simulator is showing or not.... – Girish Feb 25 '13 at 12:03
  • It works for me, don't know why not worked for you? try following link http://stackoverflow.com/questions/8738019/iphone-simulator-path-not-found – Girish Feb 25 '13 at 12:08