如何使用其名称保存和检索相册中的照片

时间:2011-06-27 07:10:41

标签: iphone photo-gallery photolibrary

我有以下疑问:

  1. 我们可以将照片(图片)保存到具有“特定名称”的相册,还是可以在保存照片后访问照片的名称?

  2. 我们可以使用相册中的名字访问照片吗?

  3. 请帮忙。

    提前致谢。

2 个答案:

答案 0 :(得分:3)

这是使用用户指定名称

编写图像的代码
 // 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]);

答案 1 :(得分:1)

使用委托UIImagePickerControllerDelegate来调用相机或图像库。

要调用相机:

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

picker.sourceType = UIImagePickerControllerSourceTypeCamera;
isCamera = YES;

[self presentModalViewController:picker animated:YES];

调用库:

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

[picker setAllowsEditing:YES];

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

完成后,将调用委托方法:

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

要将图像写入库使用:

UIImageWriteToSavedPhotosAlbum(currentImage, nil, nil, nil);

或将从照片库中挑选的所选图像保存到UIImage并对其执行进一步操作。