UIImage的旋转
2014-01-02 16:06
495 查看
以下两种方式都是用于UIImage的旋转
+(UIImage *)rotate: (UIImage *)image
{
double angle = 45;
CGSize s = {image.size.width, image.size.height};
UIGraphicsBeginImageContext(s);
CGContextRef ctx =
UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx,
0,image.size.height);
CGContextScaleCTM(ctx,
1.0, -1.0);
CGContextRotateCTM(ctx,
2*M_PI*angle/360);
CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width,
image.size.height),image.CGImage);
UIImage *newImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
+ (UIImage *)scaleAndRotateImage:(UIImage *)image {
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform =
CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0,
0, width, height);
CGFloat boundHeight;
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);
//use angle/360 *MPI
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextConcatCTM(context, transform);
CGContextDrawImage(context,
CGRectMake(0,
0, width, height), imgRef);
UIImage *imageCopy =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
+(UIImage *)rotate: (UIImage *)image
{
double angle = 45;
CGSize s = {image.size.width, image.size.height};
UIGraphicsBeginImageContext(s);
CGContextRef ctx =
UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx,
0,image.size.height);
CGContextScaleCTM(ctx,
1.0, -1.0);
CGContextRotateCTM(ctx,
2*M_PI*angle/360);
CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width,
image.size.height),image.CGImage);
UIImage *newImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
+ (UIImage *)scaleAndRotateImage:(UIImage *)image {
CGImageRef imgRef = image.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform =
CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0,
0, width, height);
CGFloat boundHeight;
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);
//use angle/360 *MPI
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context =
UIGraphicsGetCurrentContext();
CGContextConcatCTM(context, transform);
CGContextDrawImage(context,
CGRectMake(0,
0, width, height), imgRef);
UIImage *imageCopy =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
相关文章推荐
- Android Tween动画之RotateAnimation实现图片不停旋转效果实例介绍
- IOS高级教程1:处理1000张图片的内存优化
- UIImage的一个实例函数stretchableImageWithLeftCapWidth
- 如何取消屏幕旋转
- image 在页面间的传递
- iOS ios7的一些变化
- UIView设置背景图片的方法
- UIImagePickerController拍照与摄像
- NSdata 与 NSString,Byte数组,UIImage 的相互转换---ios开发 Objective-C
- 修改UINavigationController 背景颜色
- 数据存储《图片加载的性能优化》来自印象笔记
- css3之transform-styl 3D旋转效果
- 将一个DIV旋转的某一角度,任意角度,90度,放大等等问题~
- UIImage相关
- 浅谈Unity中的rotation和Quaternion的乘法
- [UIImage resizableImageWithCapInsets:] 函数说明
- 获取IPhone相册中图片的方法(ASSets)
- 图片处理 缓存
- IOS plist文件的增删操作
- Loading Images Asynchronously using NSInvocationOperation