iPhone下旋转UIImage
来源:苹果开发中文网 www.cocoadev.cn
+(UIImage *)rotateImage:(UIImage *)aImage
{
CGImageRef imgRef = aImage.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
CGFloat scaleRatio = 1;
CGFloat boundHeight;
UIImageOrientation orient = aImage.imageOrientation;
switch(orient)
{
case UIImageOrientationUp: //EXIF = 1
transform = CGAffineTransformIdentity;
break;
case UIImageOrientationUpMirrored: //EXIF = 2
transform = CGAffineTransformMakeTranslation(width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
break;
case UIImageOrientationDown: //EXIF = 3
transform = CGAffineTransformMakeTranslation(width, height);
transform = CGAffineTransformRotate(transform, M_PI);
break;
case UIImageOrientationDownMirrored: //EXIF = 4
transform = CGAffineTransformMakeTranslation(0.0, height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
break;
case UIImageOrientationLeftMirrored: //EXIF = 5
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(height, width);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
break;
case UIImageOrientationLeft: //EXIF = 6
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(0.0, width);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
break;
case UIImageOrientationRightMirrored: //EXIF = 7
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeScale(-1.0, 1.0);
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
break;
case UIImageOrientationRight: //EXIF = 8
boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
transform = CGAffineTransformMakeTranslation(height, 0.0);
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
break;
default:
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];
}
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
CGContextScaleCTM(context, -scaleRatio, scaleRatio);
CGContextTranslateCTM(context, -height, 0);
}
else {
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextTranslateCTM(context, 0, -height);
}
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
iPhone下旋转UIImage相关推荐
- 如何在不安装应用程序的情况下旋转iPhone视频
For years, iPhone users needed to download a third-party video editor app to rotate videos. With the ...
- iphone竖屏视频旋转_如何在iPhone上旋转视频
iphone竖屏视频旋转 We all know that feeling: you record a video on your iPhone in portrait mode, and then ...
- iphone强制旋转屏幕_我的iPhone或iPad屏幕无法旋转。 我如何解决它?
iphone强制旋转屏幕 Khamosh Pathak Khamosh Pathak The iPhone and the iPad screen rotates almost seamlessly ...
- 改变按钮在iPhone下的默认风格
-webkit-appearance: none; "来改变按钮在iPhone下的默认风格,其实我们可以反过来思路,使用"appearance"属性,来改变任何元素的浏览 ...
- iPhone下mp4视频无法播放和部分手机只有声音没有画面
概述 mp4视频在部分手机上加载失败.无法播放或有声音没画面的原因是:视频编码或声道数有问题,解决方案:视频转码. 遇到的问题 mp4视频在 iPhone XR (IOS 14.1) 上无法播放,一直 ...
- Ubuntu 下旋转显示器屏幕
Ubuntu 下旋转显示器屏幕 之前说到,我喜欢把显示器竖过来看网页和电子书,查了一下在Ubuntu里面旋转屏幕的方法,据说用 xrandr -o left 就可以了.不过我运行之后,遇到了这个错误: ...
- Blender图解教程:使用曲线编辑器(Graph Editor)的“不连续项(欧拉)过滤器”解决欧拉模式下旋转异常问题
情景再现 做升龙拳的时候在第25帧和第30帧之间遇到的这个问题(请注意角色脚部) 第25帧,正常的腾空勾拳pose 第30帧 也是一个正常的下落Pose 两个关键帧之间由Blender自动生成补间,然 ...
- Android模仿iPhone View旋转刷新数据动画详解
因为小马很喜欢在不同的页面之间跳转时加点好玩的动画,今天无意间看到一个动画效果感觉不错,几种效果图如下,既然好玩就写在博客中,直接说就是:该效果类似于iPhone中View的切换动画效果,今天就只介绍 ...
- iphone自动旋转与调整大小
转自http://my.oschina.net/plumsoft/blog/47289 苹果的产品iPad和iPhone都是支持自动旋转的,因而我们写的程序也要支持两种视图:纵向和横向. 默认情况下, ...
最新文章
- python count()方法
- Ubuntu 14.04+cuda 7.5+caffe安装配置
- 深度|2030年8亿人会失业!图解机器人如何取代你的工作
- 存储系统管理服务器,Mainframe的存储管理系统和架构
- 求约束条件下极值的拉格朗日乘子法
- PHP 入门 - 8.数据库
- 09.ws复杂数据类型数据传输
- ASP.NET Core ActionFilter引发的一个EF异常
- android命名管道创建使用
- oracle 表字段顺序_如何更改Oracle数据库表中字段顺序
- python是什么专业-Python是个什么鬼?为什么985学生都要学它?!
- 存储位置优化——把视图状态信息保存在服务端而非客户端
- C# UDP通讯实例
- 神经网络控制器设计原理,神经网络控制系统设计
- Qt 字体大小的计算
- python format是什么意思_python的format什么意思
- 利用selenium获取接口数据
- 我的所有知识都来自大富翁游戏
- 对nand flash设备进行升级
- 【Websocket 第三篇】消息推送