捉襟见肘之自定义自拍相机AVFoundation
因为上篇的问题的,我搜索到解决方法:
http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload
Objective-C 源代码:
#import <UIKit/UIKit.h> @interface UIImage(fixOrientation) - (UIImage *)fixOrientation; @end
UIImage+FixOrientation.h
#import "UIImage+FixOrientation.h" @implementation UIImage (fixOrientation) - (UIImage *)fixOrientation { // No-op if the orientation is already correct if (self.imageOrientation == UIImageOrientationUp) return self; // 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 (self.imageOrientation) { case UIImageOrientationDown: case UIImageOrientationDownMirrored: transform = CGAffineTransformTranslate(transform, self.size.width, self.size.height); transform = CGAffineTransformRotate(transform, M_PI); break; case UIImageOrientationLeft: case UIImageOrientationLeftMirrored: transform = CGAffineTransformTranslate(transform, self.size.width, ); transform = CGAffineTransformRotate(transform, M_PI_2); break; case UIImageOrientationRight: case UIImageOrientationRightMirrored: transform = CGAffineTransformTranslate(transform, , self.size.height); transform = CGAffineTransformRotate(transform, -M_PI_2); break; case UIImageOrientationUp: case UIImageOrientationUpMirrored: break; } switch (self.imageOrientation) { case UIImageOrientationUpMirrored: case UIImageOrientationDownMirrored: transform = CGAffineTransformTranslate(transform, self.size.width, ); transform = CGAffineTransformScale(transform, -, ); break; case UIImageOrientationLeftMirrored: case UIImageOrientationRightMirrored: transform = CGAffineTransformTranslate(transform, self.size.height, ); transform = CGAffineTransformScale(transform, -, ); break; case UIImageOrientationUp: case UIImageOrientationDown: case UIImageOrientationLeft: case UIImageOrientationRight: break; } // Now we draw the underlying CGImage into a new context, applying the transform // calculated above. CGContextRef ctx = CGBitmapContextCreate(NULL, self.size.width, self.size.height, CGImageGetBitsPerComponent(self.CGImage), , CGImageGetColorSpace(self.CGImage), CGImageGetBitmapInfo(self.CGImage)); CGContextConcatCTM(ctx, transform); switch (self.imageOrientation) { case UIImageOrientationLeft: case UIImageOrientationLeftMirrored: case UIImageOrientationRight: case UIImageOrientationRightMirrored: // Grr... CGContextDrawImage(ctx, CGRectMake(,,self.size.height,self.size.width), self.CGImage); break; default: CGContextDrawImage(ctx, CGRectMake(,,self.size.width,self.size.height), self.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; } @end
UIImage+FixOrientation.m
自定义相机完成,总结在下一篇:CoreImage初级相机图片效果处理
代码分享一下:https://github.com/nLoser/LVCamera
。。。。。。
捉襟见肘之自定义自拍相机AVFoundation的更多相关文章
- 捉襟见肘之 CoreImage初级自制相机图片效果
CoreImage.framework /* CoreImage - CoreImage.h Copyright (c) 2014 Apple, Inc. All rights reserved. * ...
- Android自定义相机拍照、图片裁剪的实现
最近项目里面又要加一个拍照搜题的功能,也就是用户对着不会做的题目拍一张照片,将照片的文字使用ocr识别出来,再调用题库搜索接口搜索出来展示给用户,类似于小猿搜题.学霸君等app. 其实Android提 ...
- 【Ray Tracing in One Weekend 超详解】 光线追踪1-8 自定义相机设计
今天,我们来学习如何设计自定义位置的相机 ready 我们只需要了解我们之前的坐标体系,或者说是相机位置 先看效果 Chapter10:Positionable camera 这一章我们直接用概念 ...
- iOS 上的相机捕捉 swift
第一台 iPhone 问世就装有相机.在第一个 SKDs 版本中,在 app 里面整合相机的唯一方法就是使用 UIImagePickerController,但到了 iOS 4,发布了更灵活的 AVF ...
- 【Unity】2.8 相机(Camera)
分类:Unity.C#.VS2015 创建日期:2016-03-31 一.简介 Unity的相机用来向玩家呈现游戏世界.你在场景中始终至少有一个相机,但也可以有多个.多个相机可以带给您双人分屏效果或创 ...
- Android 自定义Camera 随笔
一.权限 <uses-permission android:name="android.permission.CAMERA" /> <uses-permiss ...
- HTML5调用手机相机拍照
前端调用手机相机拍照 实现方式常见有两种: 一种是通过video控件,通过捕获video的流,截取video中的图像实现拍照, 还有一种是通过input[file]控件调用移动端的摄像头,实现拍照. ...
- 【腾讯优测干货】看腾讯的技术大牛如何将Crash率从2.2%降至0.2%?
小优有话说: App Crash就像地雷. 你怕它,想当它不存在.无异于让你的用户去探雷,一旦引爆,用户就没了. 你鼓起勇气去扫雷,它却神龙见首不见尾. 你告诫自己一定开发过程中减少crash,少埋点 ...
- 【重走Android之路】【开篇】序
[重走Android之路][开篇] [序] 本人Nodin,偶尔也叫MoNodin,朋友们都喜欢叫我丁,还有个笔名叫陌上幽人,文艺时叫恋风,发奋时叫不肯腐烂的土壤...也许你觉得我 ...
随机推荐
- JavaScript中call,apply,bind方法的总结。
why?call,apply,bind干什么的?为什么要学这个? 一般用来指定this的环境,在没有学之前,通常会有这些问题. var a = { user:"追梦子", fn:f ...
- OS存储器管理(二)
离散分配 分页(Paging),分段,段页式 一.分页 一个进程的物理地址可以是非连续的: 将物理内存分成固定大小的块,称为块(frame): 将逻辑内存分为同样大小的块,称为页(page): ...
- 关于Hellas和Greece
一直以来我就好奇,为什么希腊的中文名字“希腊”和英文名字”Greece”听起来都不像(就像“德国”不像“Germany”一样),而且,为什么在很多体育比赛中看到希腊运动员的衣服上都是“Hellas”, ...
- Crowdsourcing(众包)
群众外包(英语:crowdsourcing)是互联网带来的新的生产组织形式.<连线>(Wired)杂志记者Jeff Howe于2006年发明的一个专业术语,用来描述一种新的商业模式,即企业 ...
- C# 利用反射动态将字符串转换成属性对应的类型值
/// <summary> /// 为指定对象分配参数 /// </summary> /// <typeparam name="T">对象类型& ...
- 任意文件夹下打开cmd功能的设置(win10)
win10中打开cmd的方法: 1."运行"中输入CMD打开,也可以按住win+R 2.选择命令行工具中"开始-->>所有应用-->>Window ...
- Swift基础--通知,代理和block的使用抉择以及Swift中的代理
什么时候用通知,什么时候用代理,什么时候用block 通知 : 两者关系层次太深,八竿子打不着的那种最适合用通知.因为层级结构深了,用代理要一层一层往下传递,代码结构就复杂了 代理 : 父子关系,监听 ...
- 计算机网络-TCP连接
TCP首部20个字节 1.为什么TCP要三次握手建立连接? TCP连接过程,客户端发送请求到服务器,服务器确认请求发送到客户端,客户端再发送确认请求到服务器 原因:简言之,为了防止失效的连接请求发送到 ...
- java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题
File file=new File(fileAllName); FileWriter fw=new FileWriter(file); 在Java的 FileWriter 方法时 系统抛出了异常 j ...
- jquery-jsrender使用
JsRender是一款基于jQuery的JavaScript模版引擎 特点: · 简单直观 · 功能强大 · 可扩展的 · 快如闪电 jsrender使用比较简单,本文简单结束一些常用的 使用过程 ...