#pragma mark - UIImagePickerController delegate
// 选择玩图片成功回调
- ( void )imagePickerController:( UIImagePickerController *)picker didFinishPickingMediaWithInfo:( NSDictionary < NSString *, id > *)info{
[ HITAudioPlayerManagerInstacne startPalyAudioByFileName : @"bt_back" andType : @"wav" ];
[picker dismissViewControllerAnimated : YES completion : nil ];
if ( self . type == 1 ) {
if ([ self . delegate respondsToSelector : @selector (selectImageBackWithImage:)]) {
[ self . delegate selectImageBackWithImage : self . topShowImageView . image ];
[ self . navigationController popViewControllerAnimated : YES ];
return ;
}
}
// HITSubmitImageViewController *submitImageVC = [[HITSubmitImageViewController alloc]init];
// submitImageVC.submitImage = info[@"UIImagePickerControllerOriginalImage"];
// [self.navigationController pushViewController:submitImageVC animated:YES];
// UIImage *imageNew = [self scaleToSize:info[@"UIImagePickerControllerOriginalImage"] size:CGSizeMake(kSCREEN_WIDTH, kSCREEN_HEIGHT - 100)];// 上传拍照图片的处理
UIImage *image = [ self compressImage :info[ @"UIImagePickerControllerOriginalImage" ] newWidth :( kSCREEN_WIDTH , kSCREEN_HEIGHT - 100 )];
// UIImage *imageNew = [info objectForKey:@"UIImagePickerControllerEditedImage"];
// NSData *updata = UIImageJPEGRepresentation(imageNew,0.5f);
// UIImage *image = [UIImage imageWithData: updata];
AGViewController *agview = [[ AGViewController alloc ] init ];
agview. imagess = image; //UIImagePickerControllerEditedImage 修改后的图片 //UIImagePickerControllerOriginalImage 原始图片 //info[@"UIImagePickerControllerOriginalImage"]
agview. delegateImage = self ;
[ self presentViewController :agview animated : YES completion : nil ];
// 选择玩图片成功回调
- ( void )imagePickerController:( UIImagePickerController *)picker didFinishPickingMediaWithInfo:( NSDictionary < NSString *, id > *)info{
[ HITAudioPlayerManagerInstacne startPalyAudioByFileName : @"bt_back" andType : @"wav" ];
[picker dismissViewControllerAnimated : YES completion : nil ];
if ( self . type == 1 ) {
if ([ self . delegate respondsToSelector : @selector (selectImageBackWithImage:)]) {
[ self . delegate selectImageBackWithImage : self . topShowImageView . image ];
[ self . navigationController popViewControllerAnimated : YES ];
return ;
}
}
// HITSubmitImageViewController *submitImageVC = [[HITSubmitImageViewController alloc]init];
// submitImageVC.submitImage = info[@"UIImagePickerControllerOriginalImage"];
// [self.navigationController pushViewController:submitImageVC animated:YES];
// UIImage *imageNew = [self scaleToSize:info[@"UIImagePickerControllerOriginalImage"] size:CGSizeMake(kSCREEN_WIDTH, kSCREEN_HEIGHT - 100)];// 上传拍照图片的处理
UIImage *image = [ self compressImage :info[ @"UIImagePickerControllerOriginalImage" ] newWidth :( kSCREEN_WIDTH , kSCREEN_HEIGHT - 100 )];
// UIImage *imageNew = [info objectForKey:@"UIImagePickerControllerEditedImage"];
// NSData *updata = UIImageJPEGRepresentation(imageNew,0.5f);
// UIImage *image = [UIImage imageWithData: updata];
AGViewController *agview = [[ AGViewController alloc ] init ];
agview. imagess = image; //UIImagePickerControllerEditedImage 修改后的图片 //UIImagePickerControllerOriginalImage 原始图片 //info[@"UIImagePickerControllerOriginalImage"]
agview. delegateImage = self ;
[ self presentViewController :agview animated : YES completion : nil ];
}
/**
*
等比缩放本图片大小
*
* @param newImageWidth 缩放后图片宽度,像素为单位
*
* @return self-->(image)
*/
- ( UIImage *)compressImage:( UIImage *)image newWidth:( CGFloat )newImageWidth
{
if (!image) return nil ;
float imageWidth = image. size . width ;
float imageHeight = image. size . height ;
float width = newImageWidth;
float height = image. size . height /(image. size . width /width);
float widthScale = imageWidth /width;
float heightScale = imageHeight /height;
// 创建一个 bitmap 的 context
// 并把它设置成为当前正在使用的 context
UIGraphicsBeginImageContext ( CGSizeMake (width, height));
if (widthScale > heightScale) {
[image drawInRect : CGRectMake ( 0 , 0 , imageWidth /heightScale , height)];
}
else {
[image drawInRect : CGRectMake ( 0 , 0 , width , imageHeight /widthScale)];
}
// 从当前 context 中创建一个改变大小后的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext ();
// 使当前的 context 出堆栈
UIGraphicsEndImageContext ();
return newImage;
*
* @param newImageWidth 缩放后图片宽度,像素为单位
*
* @return self-->(image)
*/
- ( UIImage *)compressImage:( UIImage *)image newWidth:( CGFloat )newImageWidth
{
if (!image) return nil ;
float imageWidth = image. size . width ;
float imageHeight = image. size . height ;
float width = newImageWidth;
float height = image. size . height /(image. size . width /width);
float widthScale = imageWidth /width;
float heightScale = imageHeight /height;
// 创建一个 bitmap 的 context
// 并把它设置成为当前正在使用的 context
UIGraphicsBeginImageContext ( CGSizeMake (width, height));
if (widthScale > heightScale) {
[image drawInRect : CGRectMake ( 0 , 0 , imageWidth /heightScale , height)];
}
else {
[image drawInRect : CGRectMake ( 0 , 0 , width , imageHeight /widthScale)];
}
// 从当前 context 中创建一个改变大小后的图片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext ();
// 使当前的 context 出堆栈
UIGraphicsEndImageContext ();
return newImage;
}