可以利用这种方式实现图片UIImage翻转,本人用于自拍后,对左右相反照片的处理
来源:互联网 发布:知享科技 编辑:程序博客网 时间:2024/04/29 14:46
finishImage为需要处理的照片
在这之前需定义一下:
CGFloat DegreesToRadians(CGFloat degrees) {return degrees *M_PI / 180;};
CGFloat RadiansToDegrees(CGFloat radians) {return radians;};
UIImageView *imgView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,640, 480)];
NSData *imgData =UIImagePNGRepresentation(finishImage);
finishImage = [UIImageimageWithData:imgData];
UIImage *image=finishImage;
CGRect rect =CGRectMake(0,0,self.preview.frame.size.width,self.preview.frame.size.height);//创建矩形框
UIGraphicsBeginImageContext(rect.size);//根据size大小创建一个基于位图的图形上下文
CGContextRef currentContext =UIGraphicsGetCurrentContext();//获取当前quartz 2d绘图环境
CGContextClipToRect( currentContext, rect);//设置当前绘图环境到矩形框
CGContextDrawImage(currentContext, rect, image.CGImage);//绘图
UIImage *cropped =UIGraphicsGetImageFromCurrentImageContext();//获得图片
UIGraphicsEndImageContext();//从当前堆栈中删除quartz 2d绘图环境
finishImage=cropped;
imgView.image =finishImage;
//取出处理之后的照片
finishImage = [KCCommonimageRotatedByRadians:90andImageView:imgView];
+ (UIImage *)imageRotatedByRadians:(CGFloat)radians andImageView:(UIImageView *)imageView
{
return [KCCommonimageRotatedByDegrees:RadiansToDegrees(radians)andImageView:imageView];
}
+ (UIImage *)imageRotatedByDegrees:(CGFloat)degrees andImageView:(UIImageView *)imageView
{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIViewalloc]initWithFrame:imageView.frame];
CGAffineTransform t =CGAffineTransformMakeRotation(DegreesToRadians(degrees));
rotatedViewBox.transform = t;
CGSize rotatedSize = rotatedViewBox.frame.size;
[rotatedViewBoxrelease];
// Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap =UIGraphicsGetCurrentContext();
// Move the origin to the middle of the image so we will rotate and scale around the center.
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
// // Rotate the image context
CGContextRotateCTM(bitmap,DegreesToRadians(degrees));
// Now, draw the rotated/scaled image into the context
CGContextScaleCTM(bitmap,1.0, -1.0);
CGContextDrawImage(bitmap,CGRectMake(-imageView.frame.size.width /2, -imageView.frame.size.height /2, imageView.frame.size.width, imageView.frame.size.height), [imageView.image CGImage]);
UIImage *newImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
- 可以利用这种方式实现图片UIImage翻转,本人用于自拍后,对左右相反照片的处理
- IOS中对图片的处理 UIImage
- android更新sdk开发包(经本人实践过的,至少现在这种方式还可以实现android sdk更新)
- 绘制左右翻转的图片
- 简单的图片翻转实现方式
- 旋转翻转UIImage 不是UIImageView 适用于源图像的处理,例如截图后旋转
- 旋转翻转UIImage 不是UIImageView 适用于源图像的处理,例如截图后旋转----改变图片大小
- 左右图片翻转算法(c语言)实现
- js实现图片左右垂直翻转
- S3C6410 FrameBuffer编程(六) --- 利用FrameBuffer显示图片,并实现左右、上下、180度翻转
- S3C6410 FrameBuffer编程(六) --- 利用FrameBuffer显示图片,并实现左右、上下、180度翻转
- 各个浏览器对左右反斜杠的处理方式不同。
- 基于winform的二进制图片数据的存取(用于数据库照片的读写处理)
- Android-图片处理 之 上下,左右翻转,前景图
- Android自拍相机应用——图片的镜像翻转
- matlab实现图像的左右翻转
- 优雅的图片翻转实现方式rollover.js
- ”韦尔奇这种处理问题的方式
- 浅谈https\ssl\数字证书
- MySQL更改数据存储引擎,禁用innodb
- VS2008中为listview控件配置数据源时,“高级SQL生成选项”为灰色,无法选择!
- 2014年高校编程挑战赛奖品多多,一月份奖励措施出炉
- osg demo21 osgpraticle snow effect雪花效果
- 可以利用这种方式实现图片UIImage翻转,本人用于自拍后,对左右相反照片的处理
- 芒果数据库(MongoDB)学习记录(一)——安装
- 五分制成绩
- 数字证书文件格式(cer和pfx)的区别
- cocos2d-x Jni c++ java互调 安全刷新UI控件最简单例子(下)
- hive内置操作符与内置函数
- linux 挂在windows ntfs盘方法
- Android开发之Dialog位置以及透明度的设置
- libpcap的一些主要函数和结构介绍