IOS development-iOS calls the camera to call album [save images to a local album], ios-ios

Source: Internet
Author: User

IOS development-iOS calls the camera to call album [save images to a local album], ios-ios
Set the header proxy

<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
1. Call the camera

Check whether the front camera is available

- (BOOL)isFrontCameraAvailable{    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];}

Check whether the rear camera is available

- (BOOL)isRearCameraAvailable{    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];}

Call the camera

/// Call the camera-(void) persentImagePicker {if (! _ ImagePickerG) {// initialize the camera _ imagePickerG = [[UIImagePickerController alloc] init]; // proxy _ imagePickerG. delegate = self;} // whether the front camera is available if ([self isFrontCameraAvailable]) {_ imagePickerG. sourceType = UIImagePickerControllerSourceTypeCamera;} // whether the camera is available with else if ([self isFirstResponder]) {_ imagePickerG. sourceType = UIImagePickerControllerSourceTypeCamera;} else {[SVProgressHUD showErrorWithStatus: @ "No camera available ~ "]; Return;} // crop _ imagePickerG. allowsEditing = YES; [self. navigationController presentViewController: _ imagePickerG animated: YES completion: nil];}
2. Call album
/// Call the local album-(void) persentImagePicker {if (! _ ImagePickerG) {// initialize the camera _ imagePickerG = [[UIImagePickerController alloc] init]; // proxy _ imagePickerG. delegate = self;} // album _ imagePickerG. sourceType = UIImagePickerControllerSourceTypePhotoLibrary; _ imagePickerG. allowsEditing = YES; [self. navigationController presentViewController: _ imagePickerG animated: YES completion: nil];}
3. Proxy events
/// Deselect the image (photograph)-(void) imagePickerControllerDidCancel :( UIImagePickerController *) picker {[picker dismissViewControllerAnimated: YES completion: nil];}
/// Select image completion (completed from album or photograph)-(void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary <NSString *, id> *) info {UIImage * image = [info objectForKey: UIImagePickerControllerOriginalImage]; // source image // obtain the cropped image UIImage * imageUp = [info objectForKey: UIImagePickerControllerEditedImage];}
4. Save the image to your local device.
/// Save the image to a local album-(void) imageTopicSave :( UIImage *) image {UIImageWriteToSavedPhotosAlbum (image, self, @ selector (image: didFinishSavingWithError: contextInfo :), nil );} -(void) image :( UIImage *) image didFinishSavingWithError :( NSError *) error contextInfo :( void *) contextInfo {if (error = nil) {} else {// The image cannot be saved locally }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.