iOS图片翻转处理
来源:互联网 发布:matlab粒子群算法例子 编辑:程序博客网 时间:2024/06/06 21:44
在处理图片的过程中发现一个有意思的事情,就是有得图片选择后是呈90度翻转或者-90度翻转的情况。有得时候确实也莫名其妙。尤其是手机拍照做裁切之后,就会莫名其妙翻转。找到了解决办法在这里分享一下:
- (UIImage *)cropImage:(UIImage*)image toRect:(CGRect)rect { CGFloat (^rad)(CGFloat) = ^CGFloat(CGFloat deg) { return deg / 180.0f * (CGFloat) M_PI; }; // determine the orientation of the image and apply a transformation to the crop rectangle to shift it to the correct position CGAffineTransform rectTransform; switch (image.imageOrientation) { case UIImageOrientationLeft: rectTransform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rad(90)), 0, -image.size.height); break; case UIImageOrientationRight: rectTransform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rad(-90)), -image.size.width, 0); break; case UIImageOrientationDown: rectTransform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(rad(-180)), -image.size.width, -image.size.height); break; default: rectTransform = CGAffineTransformIdentity; }; // adjust the transformation scale based on the image scale rectTransform = CGAffineTransformScale(rectTransform, image.scale, image.scale); // apply the transformation to the rect to create a new, shifted rect CGRect transformedCropSquare = CGRectApplyAffineTransform(rect, rectTransform); // use the rect to crop the image CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage, transformedCropSquare); // create a new UIImage and set the scale and orientation appropriately UIImage *result = [UIImage imageWithCGImage:imageRef scale:image.scale orientation:image.imageOrientation]; // memory cleanup CGImageRelease(imageRef); return result;}
0 0
- iOS图片翻转处理
- IOS上传图片翻转处理重力并压缩大小
- iOS 图片翻转
- Python 图片处理-图片翻转
- Python 图片处理-图片翻转
- javascript---处理图片翻转器
- 图像处理之 图片翻转
- IOS界面(图片)翻转
- iOS 视频、图片翻转问题
- IOS翻转动画(可来回切换图片)
- PHP图片处理之图片旋转和图片翻转
- 图片翻转
- 图片翻转
- 图片翻转
- 图片翻转
- 图片翻转
- 图片翻转
- android 图片处理(图片合成、图片圆角、图片翻转、图片缩放)
- Oracle数据库创建用户,表空间,临时表空间,及授权,创建表,删除表
- iphone或android 切换不同的环境
- 使用mysql登录数据库后,如何查看当前数据库?
- Mac后台nsurlsessiond偷走流量
- Spring中MultipartHttpServletRequest实现文件上传
- iOS图片翻转处理
- 第八周项目1--建立顺序串的算法库
- C# Regex 获取xml 注释部分,并进行replace操作
- 第九周项目二(矩阵运算)
- 给 Android 开发者的 RxJava 详解
- CODEVS 1576最长严格上升子序列
- cloud-init 数据获取处理文档
- luci框架-LUA的一个web框架使用
- 经典Java面试题-内部类