我有以下疑问:
我们可以使用“特定名称”将照片(图像)保存到相册中,还是可以在保存后访问照片的名称?
我们可以从相册中访问带有其名称的照片吗?
请帮忙。
提前致谢。
我有以下疑问:
我们可以使用“特定名称”将照片(图像)保存到相册中,还是可以在保存后访问照片的名称?
我们可以从相册中访问带有其名称的照片吗?
请帮忙。
提前致谢。
这是用于编写具有用户指定名称的图像的代码
// 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]);
使用委托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
并对其执行进一步的操作。