Alb*_*haw 2 photo image objective-c save ios
我目前正以这种方式将UIImage保存到相机胶卷.
UIImageWriteToSavedPhotosAlbum(finalPicture.image, nil, nil, nil);
但是如果用户拒绝我们访问他们的照片的权限会发生什么...我怎么能告诉这已经发生并显示错误消息?
要将图像保存到相机胶卷,我正在使用ALAssetsLibrary,因此在方法中:
//Called after taking the photo with the camera or selected the image from the gallery
- (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *referenceURL;
if(Picker.sourceType==UIImagePickerControllerSourceTypeCamera){
UIImage* takenImage=info[UIImagePickerControllerOriginalImage];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Request to save the image to camera roll
[library writeImageToSavedPhotosAlbum:[takenImage CGImage] orientation:(ALAssetOrientation)[takenImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
//NOT SAVED
//DISPLAY ERROR THE PICTURE CAN'T BE SAVED
} else {
//SAVED
}
}];
}
}else{
//Selected from gallery
}
Run Code Online (Sandbox Code Playgroud)
另请记住,您必须先检查相机是否可用.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//The camera is available
}else{
//No camera available
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2420 次 |
| 最近记录: |