iOS:图片的旋转方向问题
【你知道吗?】iOS 6 默认相机程序让你的 iPhone 照片自带方向信息
可能几乎很少的人会知道在 iOS 6中有一项新的功能是用 iPhone 拍出的照片会记录该照片的方向信息。
在 iPhone 3G 开始的地理信息标记功能后,现在当你使用 iPhone 原生的摄像功能的时候,拍摄出来的照片的 metadate 中会包含有你拍摄照片的那一刻手机摄像头方向的信息。
在 iOS 6之前,想要在照片中包含方向信息,用户需要使用到一个昂贵的配件来配合数码相机使用,例如 Solmeta Geotagger N3。
据了解,这样的方向信息只会在你使用默认的拍照应用的时候才会被记录下来。如果你使用的是其它第三方摄像应用,那么拍摄出来的照片是不会包含方向信息的。如果你编辑该图片,这样的方向信息也有可能会丢失,这些都取决于图像编辑应用。
现在我也不确定这个功能是不是在所有的 iPhone 上都有,不过 iPhone 5/4S/4 都被验证,所拍图像有方向信息。
(以上文章出自:http://www.tuicool.com/articles/6Rnmey)
UIImage 有个只读属性imageOrientation 来标识它的方向。
UIImageOrientation myOrientation = myImage.imageOrientation;
// typedef enum {
// UIImageOrientationUp, // default orientation 默认方向
// UIImageOrientationDown, // 180 deg rotation 旋转180度
// UIImageOrientationLeft, // 90 deg CCW 逆时针旋转90度
// UIImageOrientationRight, // 90 deg CW 顺时针旋转90度
// UIImageOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip 向上水平翻转
// UIImageOrientationDownMirrored, // horizontal flip 向下水平翻转
// UIImageOrientationLeftMirrored, // vertical flip 逆时针旋转90度,垂直翻转
// UIImageOrientationRightMirrored, // vertical flip 顺时针旋转90度,垂直翻转
// } UIImageOrientation;
另提供图像纠正的部分代码如下供大家参考:
- - (UIImage *)fixOrientation:(UIImage *)srcImg {
- if (srcImg.imageOrientation == UIImageOrientationUp) return srcImg;
- CGAffineTransform transform = CGAffineTransformIdentity;
- switch (srcImg.imageOrientation) {
- case UIImageOrientationDown:
- case UIImageOrientationDownMirrored:
- transform = CGAffineTransformTranslate(transform, srcImg.size.width, srcImg.size.height);
- transform = CGAffineTransformRotate(transform, M_PI);
- break;
- case UIImageOrientationLeft:
- case UIImageOrientationLeftMirrored:
- transform = CGAffineTransformTranslate(transform, srcImg.size.width, 0);
- transform = CGAffineTransformRotate(transform, M_PI_2);
- break;
- case UIImageOrientationRight:
- case UIImageOrientationRightMirrored:
- transform = CGAffineTransformTranslate(transform, 0, srcImg.size.height);
- transform = CGAffineTransformRotate(transform, -M_PI_2);
- break;
- case UIImageOrientationUp:
- case UIImageOrientationUpMirrored:
- break;
- }
- switch (srcImg.imageOrientation) {
- case UIImageOrientationUpMirrored:
- case UIImageOrientationDownMirrored:
- transform = CGAffineTransformTranslate(transform, srcImg.size.width, 0);
- transform = CGAffineTransformScale(transform, -1, 1);
- break;
- case UIImageOrientationLeftMirrored:
- case UIImageOrientationRightMirrored:
- transform = CGAffineTransformTranslate(transform, srcImg.size.height, 0);
- transform = CGAffineTransformScale(transform, -1, 1);
- break;
- case UIImageOrientationUp:
- case UIImageOrientationDown:
- case UIImageOrientationLeft:
- case UIImageOrientationRight:
- break;
- }
- CGContextRef ctx = CGBitmapContextCreate(NULL, srcImg.size.width, srcImg.size.height,
- CGImageGetBitsPerComponent(srcImg.CGImage), 0,
- CGImageGetColorSpace(srcImg.CGImage),
- CGImageGetBitmapInfo(srcImg.CGImage));
- CGContextConcatCTM(ctx, transform);
- switch (srcImg.imageOrientation) {
- case UIImageOrientationLeft:
- case UIImageOrientationLeftMirrored:
- case UIImageOrientationRight:
- case UIImageOrientationRightMirrored:
- CGContextDrawImage(ctx, CGRectMake(0,0,srcImg.size.height,srcImg.size.width), srcImg.CGImage);
- break;
- default:
- CGContextDrawImage(ctx, CGRectMake(0,0,srcImg.size.width,srcImg.size.height), srcImg.CGImage);
- break;
- }
- CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
- UIImage *img = [UIImage imageWithCGImage:cgimg];
- CGContextRelease(ctx);
- CGImageRelease(cgimg);
- return img;
- }
- 转载自:http://blog.csdn.net/demoker/article/details/21806291?utm_source=tuicool
iOS:图片的旋转方向问题相关推荐
- speedoffice(PPT)图片怎么旋转方向
我们有时向PPT插入的图片方向不是正的,这时候就需要旋转图片?那么PPT里面图片怎么旋转呢?看看小编是怎么操作的吧. 方法1:选中图片后,我们可以看到图片边框出现旋转图标,光标放在图标上拖动鼠标即可旋 ...
- ios 图片逆时针旋转_iphone-IOS 竖直拍照被旋转,image-orientation 让图片自动旋转
本文目录结构 IOS 垂直拍照的时候会遇到,PC 端读取的时候,逆时针旋转了 90 度的问题: 安卓.PS 处理的,相册选择截图等不会出现这个问题: 场景说明: 这个图片在浏览器里,如果您单独打开的时 ...
- IOS 图片自动旋转
+ (UIImageView *)rotate360DegreeWithImage View:(UIImageView *)imageView{ CABasicAnimation *ani ...
- 解决H5 IOS手机图片上传时图片会旋转90°问题
解决H5 IOS手机图片上传时图片会旋转90°问题 Vant 官方给出的解答需要自己解决,没有处理. 解决办法主要使用了 compressorjs 插件库 一.Vant UI库Uploader 组件图 ...
- 上传图片的时候,ios手机的图片会旋转90°
1.问题:在html5中利用canvas对上传图片压缩的时候,ios手机竖着拍照时,图片会旋转90°,其他情况正常. 2.解决方法:获取拍照角度,对Ios竖着拍的照片进行角度处理 3.利用exif.j ...
- ios 拍照上传到服务器_ios端浏览器拍照上传到服务器,图片被旋转90度 php 解决方案...
1.可以通过前端进行解决,本案例通过后端解决的 判断请求的浏览器的ua,如果是ios浏览器则进行90度旋转 重点来了: 必须确保检测的图片是ios设备上传的完整图片,不要在前端压缩过的,因为压缩后的图 ...
- IOS基础之iPad的屏幕旋转方向判断
IOS基础之iPad的屏幕旋转方向判断 #pragma mark - 屏幕旋转 - (void)viewWillTransitionToSize:(CGSize)size withTransition ...
- exif.js html图片旋转,解决图片显示 Exif.js更改图片的显示方向
没什么文字直接上代码 //这是一个解决exif更改脱方向的一个js文件 // 应用前先npm install exif-js --save或者直接引入exif-js 调用方法 // let baseD ...
- iOS-image图片旋转方向
最近在做项目的时候发现资源包内的图片的方向不对,但也不想让UI切一个新图,所以需要将原有的图片改变其方向. UIImage *backImage = [UIImage imageNamed:@&quo ...
最新文章
- java中jar打包的方法
- 简单c语言图形界面,求个用最简单的的代码来实现图形界面…
- android四中启动模式
- web服务器是如何维护,我们如何维护Web客户端和Web服务器之间的会话?
- html文档打开错误,我的html的文档无法打开,打开也是报错
- 王道8套有变化吗_求求你别再套花艺设计公式了
- subline Text3 插件安装
- 再送 5000 份红包封面!
- 思科:多款主流信息传递应用程序易遭到会话劫持
- XtuningTheBert
- 小白怎么入门网络安全?
- python去除空行_Python中去除文件空行(strip)
- Windows与USB的通信
- 记笔记格式 — markdown 语法
- Android 大众点评的接入
- 算法第一章作业(c++代码规范+数学之美读后感+规划)
- 全球与中国用于食品饮料工艺的隔膜阀市场现状及未来发展趋势
- 进阶39 奇妙的数字
- 怎样实现远程桌面的连接
- java计算机毕业设计考试编排管理系统MyBatis+系统+LW文档+源码+调试部署