// // StampImageViewController.m // PDFReader // // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved. // // The PDF Reader Sample applications are licensed with a modified BSD license. // Please see License for details. This notice may not be removed from this file. // #import "StampImageViewController.h" @interface StampImageViewController () @property (nonatomic,retain) UIImagePickerController *imagePickerController; @end @implementation StampImageViewController #pragma mark - Init Methods - (void)dealloc { Block_release(_callback); _imagePickerController.delegate = nil; [_imagePickerController release]; [super dealloc]; } #pragma mark - UIViewController Methods - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self.navigationController.navigationBar setTranslucent:NO]; self.view.backgroundColor = [UIColor whiteColor]; self.title = NSLocalizedString(@"New Image Stamp", nil); _imagePickerController = [[UIImagePickerController alloc] init]; _imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; _imagePickerController.delegate = self; _imagePickerController.allowsEditing = NO; _imagePickerController.navigationBar.hidden = YES; [self.view addSubview:_imagePickerController.view]; } #pragma mark - UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = nil; if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { image = [info objectForKey:UIImagePickerControllerEditedImage]; } else { image = [info objectForKey:UIImagePickerControllerOriginalImage]; } [picker dismissViewControllerAnimated:YES completion:nil]; UIImageOrientation imageOrientation = image.imageOrientation; if (imageOrientation != UIImageOrientationUp) { UIGraphicsBeginImageContext(image.size); [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); } if (!image) { UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:nil]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Error", nil) message:NSLocalizedString(@"Error:image is null !", nil) preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:okAction]; [self.navigationController presentViewController:alert animated:YES completion:nil]; } [self.navigationController popToRootViewControllerAnimated:YES]; if (self.callback) { self.callback(image); self.callback = nil; } } @end