- (UIImage*)scaleImage:(UIImage*)anImage withEditingInfo:(NSDictionary*)editInfo{
UIImage *newImage;
UIImage *originalImage = [editInfo valueForKey:@"UIImagePickerControllerOriginalImage"];
CGSize originalSize = CGSizeMake(originalImage.size.width, originalImage.size.height);
CGRect originalFrame;
originalFrame.origin = CGPointMake(0,0);
originalFrame.size = originalSize;
CGRect croppingRect = [[editInfo valueForKey:@"UIImagePickerControllerCropRect"] CGRectValue];
CGSize croppingRectSize = CGSizeMake(croppingRect.size.width, croppingRect.size.height);
CGSize croppedScaledImageSize = anImage.size;
float scaledBarClipHeight = 80;
CGSize scaledImageSize;
float scale;
if(!CGSizeEqualToSize(croppedScaledImageSize, originalSize)){
scale = croppedScaledImageSize.width/croppingRectSize.width;
float barClipHeight = scaledBarClipHeight/scale;
croppingRect.origin.y -= barClipHeight;
croppingRect.size.height += (2*barClipHeight);
if(croppingRect.origin.y<=0){
croppingRect.size.height += croppingRect.origin.y;
croppingRect.origin.y=0;
}
if(croppingRect.size.height > (originalSize.height - croppingRect.origin.y)){
croppingRect.size.height = (originalSize.height - croppingRect.origin.y);
}
scaledImageSize = croppingRect.size;
scaledImageSize.width *= scale;
scaledImageSize.height *= scale;
newImage = [self cropImage:originalImage to:croppingRect andScaleTo:scaledImageSize];
}else{
newImage = originalImage;
}
return newImage;
}

相对应回调处理

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
[self dismissModalViewControllerAnimated:YES];
self.myImageView.userInteractionEnabled=YES;
CGRect imageFrame = myImageView.frame;
CGPoint imageCenter = myImageView.center;
UIImage *croppedImage;
NSMutableDictionary *imageDescriptor = [editInfo mutableCopy];
// CGFloat scaleSize = 400.0f;
CGFloat scaleSize = 640.0f;
switch ([picker sourceType]) {
//done
case UIImagePickerControllerSourceTypePhotoLibrary:
croppedImage = [self scaleImage:img withEditingInfo:editInfo];
[imageDescriptor setObject:croppedImage forKey:@"croppedImage"];
break;
case UIImagePickerControllerSourceTypeCamera: {
UIImageOrientation originalOrientation = [[editInfo objectForKey:UIImagePickerControllerOriginalImage] imageOrientation];
if (originalOrientation != UIImageOrientationUp) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect origRect;
[[editInfo objectForKey:UIImagePickerControllerCropRect] getValue:&origRect];
UIImage *rotatedImage = straightenAndScaleImage([editInfo objectForKey:UIImagePickerControllerOriginalImage], scaleSize);
CGFloat scale = scaleSize/1600.0f;
origRect.origin.x *= scale;
origRect.origin.y *= scale;
origRect.size.width *= scale;
origRect.size.height *= scale;
croppedImage = [self cropImage:rotatedImage to:origRect andScaleTo:CGSizeMake(320, 480)];
[imageDescriptor setObject:croppedImage forKey:@"croppedImage"];
[pool drain];
}
else {
croppedImage = [self scaleImage:img withEditingInfo:editInfo];
[imageDescriptor setObject:croppedImage forKey:@"croppedImage"];
}
}
break;
case UIImagePickerControllerSourceTypeSavedPhotosAlbum: {
UIImageOrientation originalOrientation = [[editInfo objectForKey:UIImagePickerControllerOriginalImage] imageOrientation];
if (originalOrientation != UIImageOrientationUp) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect origRect;
[[editInfo objectForKey:UIImagePickerControllerCropRect] getValue:&origRect];
UIImage *rotatedImage = straightenAndScaleImage([editInfo objectForKey:UIImagePickerControllerOriginalImage], scaleSize);
CGFloat scale = scaleSize/640.0f;
origRect.origin.x *= scale;
origRect.origin.y *= scale;
origRect.size.width *= scale;
origRect.size.height *= scale;
croppedImage = [self cropImage:rotatedImage to:origRect andScaleTo:CGSizeMake(320, 480)];
[imageDescriptor setObject:croppedImage forKey:@"croppedImage"];
[pool drain];
}
else {
croppedImage = [self scaleImage:img withEditingInfo:editInfo];
[imageDescriptor setObject:croppedImage forKey:@"croppedImage"];
}
}
break;
default:
break;
}
imageFrame.size = croppedImage.size;
myImageView.frame = imageFrame;
myImageView.image = [imageDescriptor objectForKey:@"croppedImage"];
myImageView.center = imageCenter;
}

UIImagePickerController关于图片裁剪的更多相关文章

  1. iOS常见用户头像的圆形图片裁剪常见的几种方法

    在开发中,基本上APP的用户头像的处理都需要把用户所上传的方形图片,处理为圆形图片.在这里就总结三种常见的处理圆形图片的方法. 1.使用位图上下文 2.使用UIView的layer进行处理 3.使用r ...

  2. Cropper – 简单的 jQuery 图片裁剪插件

    Cropper 是一个简单的 jQuery 图像裁剪插件.它支持选项,方法,事件,触摸(移动),缩放,旋转.输出的裁剪数据基于原始图像大小,这样你就可以用它们来直接裁剪图像. 如果你尝试裁剪跨域图像, ...

  3. 自己积累的一些Emgu CV代码(主要有图片格式转换,图片裁剪,图片翻转,图片旋转和图片平移等功能)

    using System; using System.Drawing; using Emgu.CV; using Emgu.CV.CvEnum; using Emgu.CV.Structure; na ...

  4. web开发实战--图片裁剪和上传

    前言: 最近的开发中, 有一个上传头像的任务. 由于头像本身的特殊性, 其一般流程为选择图片, 编辑裁剪区域, 再继而上传图片操作. 看似简单的东西, 实则是挺麻烦的一件事. 借助这次开发机会, 来具 ...

  5. PHP图片裁剪_图片缩放_PHP生成缩略图

    在制作网页过程中,为了排版整齐美观,对网页中的图片处理成固定大小尺寸的图片,或是要截去图片边角中含有水印的图片,对于图片量多,每天更新大量图,靠人工PS处理是不现实的,那么有没有自动处理图片的程序了! ...

  6. Croppic – 免费开源的 jQuery 图片裁剪插件

    Croppic 这款开源的 jQuery 图片裁剪插件能够满足网站开发人员各种不同的使用需要.只需要简单的上传图片,就可以实现你想要的图像缩放和裁剪功能.因为使用了 HTML5 FormData  对 ...

  7. Android大图片裁剪终极解决方案(上:原理分析)

    转载声明:Ryan的博客文章欢迎您的转载,但在转载的同时,请注明文章的来源出处,不胜感激! :-)  http://my.oschina.net/ryanhoo/blog/86842 约几个月前,我正 ...

  8. apiCloud中图片裁剪模块FNImageClip的使用

    思路 1.获取需裁剪图片的地址 2.跳转到裁剪页面 3.裁剪成功返回新图片地址 4.替换原有图片地址 增加修饰和事件 str += '<li class="tu image" ...

  9. ASP.NET MVC在服务端把异步上传的图片裁剪成不同尺寸分别保存,并设置上传目录的尺寸限制

    我曾经试过使用JSAjaxFileUploader插件来把文件.照片以异步的方式上传,就像"MVC文件图片ajax上传轻量级解决方案,使用客户端JSAjaxFileUploader插件01- ...

随机推荐

  1. 快速开发框架(FDMS)新增1000个对外接口都不须要手写一行代码

    一个大型系统难免会跟其它系统有数据交换,这里就要提供数据接口给外部系统. 曾经在一家智能终端设备的公司上班.那段时间的主要工作就是写接口.接口须要与手机.手持设备.系统管理软件等进行数据交换.总结了一 ...

  2. tengine + lua 实现流量拷贝

    环境搭建参考地址:http://www.cnblogs.com/cp-miao/p/7505910.html cp.lua local res1, res2, action action = ngx. ...

  3. MVC Movie App

    ylbtech- ASP.NET MVC:MVC Movie App 功能描述:MVC Movie App 2,TechnologyAndTheEnvironment(技术与环境) 操作系统: win ...

  4. 异常值监测的方法 Tukey test

    参考: https://www.zhihu.com/question/38066650

  5. 基于3D Vision眼镜的OSG立体显示 【转】

    http://blog.csdn.net/qq_20038925/article/details/50510565 OSG 立体显示 3D Vision眼镜:所实现的是被动立体. 1.本人最近在做os ...

  6. vim删除文本文件中末行^M

    ^M字符的来历和作用:在DOS/Windows里,文本文件的换行符为\r\n,而在*nix系统里则为\n,所以DOS/Windows里编辑过的文本文件到了*nix里,每一行都多了个^M.所以^M只是一 ...

  7. RocketMQ之连接以及连接缓存

    发现rabbitmq有一个ConnectionFactory.发现rocketmq好像没这个东西.按道理来说如果每次发送消息都新建一条连接肯定是不可能的. ps:其实之所以是有上面的疑问是因为数据库连 ...

  8. easyUI表头样式

    easyUI表头样式 学习了:https://blog.csdn.net/lucasli2016/article/details/53606609 easyUI的样式定义在easyui.css中 表头 ...

  9. Android API Guides---Host-based Card Emulation

    Host-based Card Emulation 很多提供NFC功能的Andr​​oid手机已经支持NFC卡模拟.在大多数情况下.该卡是由在该装置的单独芯片仿真,称为安全元件. 无线运营商提供了非常 ...

  10. $ gulp watch 运行出错解决方法

    $ gulp watch 运行出错解决方法   $ gulp watch     如果你出现了如下报错信息: gulp-notify: [Laravel Elixir] Browserify Fail ...