StampImageViewController.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // StampImageViewController.m
  3. // PDFReader
  4. //
  5. // Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // The PDF Reader Sample applications are licensed with a modified BSD license.
  8. // Please see License for details. This notice may not be removed from this file.
  9. //
  10. #import "StampImageViewController.h"
  11. @interface StampImageViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
  12. @property (nonatomic,retain) UIImagePickerController *imagePickerController;
  13. @end
  14. @implementation StampImageViewController
  15. #pragma mark - Init Methods
  16. - (void)dealloc {
  17. Block_release(_callback);
  18. _imagePickerController.delegate = nil;
  19. [_imagePickerController release];
  20. [super dealloc];
  21. }
  22. #pragma mark - UIViewController Methods
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self.navigationController.navigationBar setTranslucent:NO];
  27. self.view.backgroundColor = [UIColor whiteColor];
  28. self.title = NSLocalizedString(@"New Image Stamp", nil);
  29. _imagePickerController = [[UIImagePickerController alloc] init];
  30. _imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  31. _imagePickerController.delegate = self;
  32. _imagePickerController.allowsEditing = NO;
  33. _imagePickerController.navigationBar.hidden = YES;
  34. [self.view addSubview:_imagePickerController.view];
  35. }
  36. #pragma mark - UIImagePickerControllerDelegate
  37. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  38. UIImage *image = nil;
  39. if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
  40. image = [info objectForKey:UIImagePickerControllerEditedImage];
  41. } else {
  42. image = [info objectForKey:UIImagePickerControllerOriginalImage];
  43. }
  44. [picker dismissViewControllerAnimated:YES completion:nil];
  45. UIImageOrientation imageOrientation = image.imageOrientation;
  46. if (imageOrientation != UIImageOrientationUp) {
  47. UIGraphicsBeginImageContext(image.size);
  48. [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
  49. image = UIGraphicsGetImageFromCurrentImageContext();
  50. UIGraphicsEndImageContext();
  51. }
  52. if (!image) {
  53. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
  54. style:UIAlertActionStyleDefault
  55. handler:nil];
  56. UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Error", nil)
  57. message:NSLocalizedString(@"Error:image is null !", nil)
  58. preferredStyle:UIAlertControllerStyleAlert];
  59. [alert addAction:okAction];
  60. [self.navigationController presentViewController:alert animated:YES completion:nil];
  61. }
  62. [self.navigationController popToRootViewControllerAnimated:YES];
  63. if (self.callback) {
  64. self.callback(image);
  65. self.callback = nil;
  66. }
  67. }
  68. @end