iPhone下旋转UIImage
来源:互联网 发布:alphago原理 知乎 编辑:程序博客网 时间:2024/06/02 11:11
来源:苹果开发中文网 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 UIImage扩展方法,支持放大和旋转 (转)
- UIImage旋转
- Iphone UIImage
- 如何旋转rotate UIImage
- UIImage的旋转
- UIImage图像旋转
- 如何旋转rotate UIImage
- UIImage的旋转
- UIImage旋转详解
- iOS UIImage 图像旋转
- iphone UIImage常用方法
- [IPhone] 如何缩小UIImage
- IPhone之UIImage
- iphone--UIImage图片拉伸
- iphone缩小uIImage图片
- iphone缩小uIImage图片
- iphone UIImage用法介绍
- 建网站的那些事(4)--- 网站域名
- 今天我正式开始我的csdn之旅!!!
- LIMS系统开发经历----之一(需求分析(初步))
- 调用getNextException查看原因(转)
- 求平面切割三角形的交线
- iPhone下旋转UIImage
- Pwn2Own 2010即将开幕 Chrome能否成功卫冕?
- 为何要用封装(Encapsulation)
- 火箭队又输了一场,郁闷
- oracle SQL分类
- 【转】我的大学
- linux c读取proc
- 一道老智力题
- 物联网