http://www.tuicool.com/articles/IfEZre

今天写demo的时候发现, 如果把通过相机获取到的图片,直接进行操作, 比如裁剪, 缩放, 则会把原图片向又旋转90度。

刚开始觉得莫名其妙, 不知所措。 后来百度了一下,找到了解决办法。

ps: 查找过程中, 碰到了一种说法:

//get original photo from iOS photos
//如果该图片大于2M,会自动旋转90度;否则不旋转
UIImage* originalImg=[dict objectForKey:UIImagePickerControllerOriginalImage];

至于是否正确, 还没确定。 先Mark。

下面的解决办法亲测可行。 原文:http://www.cnblogs.com/jiangyazhou/archive/2012/03/22/2412343.html

用相机拍摄出来的照片含有EXIF信息,UIImage的imageOrientation属性指的就是EXIF中的orientation信息。

如果我们忽略orientation信息,而直接对照片进行像素处理或者drawInRect等操作,得到的结果是翻转或者旋转90之后的样子。这是因为我们执行像素处理或者drawInRect等操作之后,imageOrientaion信息被删除了,imageOrientaion被重设为0,造成照片内容和imageOrientaion不匹配。

所以,在对照片进行处理之前,先将照片旋转到正确的方向,并且返回的imageOrientaion为0。

下面这个方法就是一个UIImage category中的方法,用它可以达到以上目的。

- (UIImage *)fixOrientation:(UIImage *)aImage {

  // No-op if the orientation is already correct
  if (aImage.imageOrientation == UIImageOrientationUp)   return aImage;   // We need to calculate the proper transformation to make the image upright.  // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.  CGAffineTransform transform = CGAffineTransformIdentity;   switch (aImage.imageOrientation) {   case UIImageOrientationDown:   case UIImageOrientationDownMirrored:    transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);    transform = CGAffineTransformRotate(transform, M_PI);    break;      case UIImageOrientationLeft:   case UIImageOrientationLeftMirrored:    transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);    transform = CGAffineTransformRotate(transform, M_PI_2);    break;      case UIImageOrientationRight:   case UIImageOrientationRightMirrored:    transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);    transform = CGAffineTransformRotate(transform, -M_PI_2);    break;   default:    break;  }   switch (aImage.imageOrientation) {   case UIImageOrientationUpMirrored:   case UIImageOrientationDownMirrored:    transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);    transform = CGAffineTransformScale(transform, -1, 1);    break;      case UIImageOrientationLeftMirrored:   case UIImageOrientationRightMirrored:    transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);    transform = CGAffineTransformScale(transform, -1, 1);    break;   default:    break;  }   // Now we draw the underlying CGImage into a new context, applying the transform  // calculated above.  CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,            CGImageGetBitsPerComponent(aImage.CGImage), 0,            CGImageGetColorSpace(aImage.CGImage),            CGImageGetBitmapInfo(aImage.CGImage));  CGContextConcatCTM(ctx, transform);  switch (aImage.imageOrientation) {   case UIImageOrientationLeft:   case UIImageOrientationLeftMirrored:   case UIImageOrientationRight:   case UIImageOrientationRightMirrored:    // Grr...    CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);    break;      default:    CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);    break;  }   // And now we just create a new UIImage from the drawing context  CGImageRef cgimg = CGBitmapContextCreateImage(ctx);  UIImage *img = [UIImage imageWithCGImage:cgimg];  CGContextRelease(ctx);  CGImageRelease(cgimg);  return img; }

转载于:https://www.cnblogs.com/itlover2013/p/4957259.html

iOS开发- 相机(摄像头)获取到的图片自动旋转90度解决办法相关推荐

  1. iOS照相机获取到的图片自动旋转90度解决办法

    情景再现: iOS开发过程中,要实现用用手机摄像头拍一张照片,经过裁剪压缩,然后发出去.结果发出去的图片始终是逆时针旋转了90度的图片. 事出有因: 相机拍照后直接取出来的UIimage(用UIIma ...

  2. 解决ios横屏拍照图片自动旋转90度问题

    解决ios横屏拍照图片自动旋转90度问题 参考文章: (1)解决ios横屏拍照图片自动旋转90度问题 (2)https://www.cnblogs.com/lanshengzhong/p/900856 ...

  3. 图片旋转90度解决办法

    如果把通过相机获取到的图片,直接进行操作, 比如裁剪, 缩放, 则会把原图片向又旋转90度. ps: 查找过程中, 碰到了一种说法: [objc]  view plain copy //get ori ...

  4. html中如何使图片自动旋转90度,css怎么让图片旋转90度?

    css怎么让图片旋转90度?下面本篇文章给大家介绍一下使用CSS让图片旋转90度的方法.有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助. css怎么让图片旋转90度? 在CSS中,可以 ...

  5. html中如何使图片自动旋转90度,css实现图片旋转90度的方法

    css实现图片旋转90度的方法 发布时间:2020-08-31 11:44:39 来源:亿速云 阅读:550 作者:小新 小编给大家分享一下css实现图片旋转90度的方法,相信大部分人都还不怎么了解, ...

  6. 相机获取的照片向左自动旋转90度解决方法

    用相机拍摄出来的照片含有EXIF信息,UIImage的imageOrientation属性指的就是EXIF中的orientation信息. 如果我们忽略orientation信息,而直接对照片进行像素 ...

  7. ios 拍照上传到服务器_ios端浏览器拍照上传到服务器,图片被旋转90度 php 解决方案...

    1.可以通过前端进行解决,本案例通过后端解决的 判断请求的浏览器的ua,如果是ios浏览器则进行90度旋转 重点来了: 必须确保检测的图片是ios设备上传的完整图片,不要在前端压缩过的,因为压缩后的图 ...

  8. 图片旋转90度解决的方法

    假设把通过相机获取到的图片,直接进行操作, 比方裁剪, 缩放, 则会把原图片向又旋转90度. ps: 查找过程中, 碰到了一种说法: [objc]  view plain copy //get ori ...

  9. 摄像头camera 旋转90度 解决方法

    拍照需要竖屏时的解决方法. zxing官方wiki上面的解决办法. 基本思路如下. There are 4 relative files: 1.manifest.xml, you need to ma ...

最新文章

  1. hello rocketMQ
  2. 检索数据_20_按照字符串数字组合的排序
  3. Android之Fragment(一)
  4. Android初级教程初谈自定义view自定义属性
  5. 电脑硬件名称 中英文对照
  6. 《金字塔原理》要点汇总
  7. Selenium官网教程
  8. android wps mac 下载地址,wps for mac下载
  9. 面试必备 | 带你彻底搞懂 Python 生成器。
  10. 图解谷歌浏览器Chrome的Logo_longware_新浪博客
  11. 为你的企业建立竞争情报系统
  12. 微信企业号回调模式 java_java微信企业号开发之开发模式的开启
  13. 样式的新建、修改和导入/导出
  14. Day7 零基础python入门100天Udemy训练营-Hangman Game 继续学习import, if else, while loop, for loop
  15. linux php-fpm 配置文件,linux下php-fpm开启与关闭方法
  16. 【微软资源站】MSDN
  17. KubeSphere 社区双周报 | KubeKey v3.0.2 发布 | 2022-11-24
  18. malloc函数未定义
  19. 局域网无法访问发布的网站问题解决
  20. 为什么win32k.sys在System进程空间无法访问

热门文章

  1. 【STM32】待机唤醒程序示例
  2. 【Linux驱动】linux内核模块简介
  3. druid连接池初始化慢_从零开始手写 mybatis (三)jdbc pool 从零实现数据库连接池
  4. S如何边缘控制_如何用尼康佳能索尼人像标头50mm/1.8拍出大片的效果?
  5. 命令点无效怎么处理_怎么更好处理闲置包包,买包卖包都要记住这5点
  6. go iscoinbase()_《电车GO!驰骋吧山手线》新情报:高分攻略与新模式介绍
  7. 删除链表的倒数第N个节点—leetcode19
  8. display block 无法显示_display:inline-block产生的问题
  9. 机器学习是什么——周志华
  10. 记录 之 numpy查看数据类型和类型转换