// // HdlCorpImageViewController.m // HDL_Widget_iOS // // Created by HDL on 2019/10/17. // Copyright © 2019 JLChen. All rights reserved. // #import "HdlCorpImageViewController.h" #import "UIImage+Crop.h" #import "CropImageController.h" #define WEAKSELF_AT __weak __typeof(&*self)weakSelf_AT = self; @interface HdlCorpImageViewController ()<CropImageDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> @property (nonatomic, strong) NSString *mCropPicturePath; //图片路径 @property (nonatomic, strong) NSString *mCropPictureName; //图片命å @end @implementation HdlCorpImageViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; _mCropPictureName = @"hdl_headPicture.Png"; if(_openType == 101){ [self openTypeCamera]; }else{ [self openTypePhotoLibrary]; } // Do any additional setup after loading the view. } #pragma mark - ä¸Šä¼ å¤´åƒ -(void)openTypeCamera{ WEAKSELF_AT UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = weakSelf_AT; imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController:imagePickerController animated:YES completion:nil]; } -(void)openTypePhotoLibrary;{ WEAKSELF_AT UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = weakSelf_AT; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:imagePickerController animated:YES completion:nil]; } #pragma mark -- UIImagePickerControllerDelegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:nil]; // [picker dismissViewControllerAnimated:YES completion:^{ // // }]; // [picker dismissViewControllerAnimated:YES completion:^{ // UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; // CropImageController * con = [[CropImageController alloc] initWithImage:image delegate:self]; // [self.navigationController pushViewController:con animated:YES]; // }]; UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; CGFloat width = [UIScreen mainScreen].bounds.size.width; CGFloat height = image.size.height * (width/image.size.width); UIImage * orImage = [image resizeImageWithSize:CGSizeMake(width, height)]; CropImageController * con = [[CropImageController alloc] initWithImage:orImage delegate:self]; con.ovalClip = NO; [self.navigationController pushViewController:con animated:YES]; } // å–æ¶ˆå›¾ç‰‡é€‰æ‹©è°ƒç”¨æ¤æ–¹æ³• - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self backAction:NO]; } -(void)backAction:(BOOL)bGetPicture{ if(bGetPicture){ if(self.mSaveImageCallBack != NULL){ [self.mSaveImageCallBack SaveImageCallBack:_mCropPicturePath]; NSLog(@"å…³é—页é¢"); } } [self.navigationController popViewControllerAnimated:YES]; } #pragma mark -- CropImageDelegate - (void)cropImageDidFinishedWithImage:(NSString *)imageName bSuccess:(BOOL)bSuccess{ if(bSuccess){ //ä¿å˜åˆ°æœ¬åœ°å¹¶è¿”回路径 // _mCropPicturePath // NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES); // // NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent: // [NSString stringWithFormat:@"%@", _mCropPictureName]]; // ä¿å˜æ–‡ä»¶çš„åç§° // // BOOL result =[UIImagePNGRepresentation(image)writeToFile:filePath atomically:YES]; // ä¿å˜æˆåŠŸä¼šè¿”å›žYES // if (result == YES) { //// _mCropPicturePath =_mCropPictureName; // _mCropPicturePath =filePath; // NSLog(@"ä¿å˜æˆåŠŸ"); // } _mCropPicturePath = imageName; [self backAction:bSuccess]; }else{ [self backAction:bSuccess]; } } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end