1

I have the following doubts:

  1. Can we save a photo(image) to photo album with a "specific name" or can we access the name of the photo after saving it?

  2. Can we access a photo with its name from the photo album?

Please help.

Thanks in advance.

bpeterson76
  • 12,918
  • 5
  • 49
  • 82
Satya
  • 3,320
  • 1
  • 20
  • 19

2 Answers2

3

This is the code for writing images with user specified name

 // Create paths to output images
 NSString  *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.png"];
 NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];

 // Write a UIImage to JPEG with minimum compression (best quality)
 // The value 'image' must be a UIImage object
 // The value '1.0' represents image compression quality as value from 0.0 to 1.0
 [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];

 // Write image to PNG
 [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];

 // Let's check to see if files were successfully written...

 // Create file manager
 NSError *error;
 NSFileManager *fileMgr = [NSFileManager defaultManager];

 // Point to Document directory
 NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

 // Write out the contents of home directory to console
 NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
Janak Nirmal
  • 22,706
  • 18
  • 63
  • 99
Asish AP
  • 4,421
  • 2
  • 28
  • 50
  • Thanks for responding to my question. Actually, I need to save the photos to photo album with specific name, not the document directory. – Satya Jun 27 '11 at 07:38
1

Using delegate UIImagePickerControllerDelegate for invoking camera or image library.

To Invoke Camera:

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

picker.sourceType = UIImagePickerControllerSourceTypeCamera;
isCamera = YES;

[self presentModalViewController:picker animated:YES];

To Invoke Library:

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

[picker setAllowsEditing:YES];

[self presentModalViewController:(UIViewController*)picker animated:YES];

Once done, delegate method gets called:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

To write image to library use:

UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);

or save selected image picked from photo library to UIImage and perform further actions on it.

DarthJDG
  • 16,511
  • 11
  • 49
  • 56
JainAnk
  • 205
  • 3
  • 13
  • @JaninAnk: Hi, I know how to use imagePicker and save image etc. But my doubt is, how to save and access those images with specific names. – Satya Jun 27 '11 at 07:40
  • Your program is not allowed to save things outside of its "sand box". – JainAnk Jun 27 '11 at 10:05