UIImageView 动画 / UIImage 方向
UIImage 方向
UIImage imageOrientation是相对当前屏幕的横竖屏来判断方向
如果本身是横屏, 照片也是横屏的话, 方向是正方向
BOOL b1 = (originalImage.imageOrientation == UIImageOrientationUp || originalImage.imageOrientation == UIImageOrientationDown);
BOOL b2 = (originalImage.imageOrientation == UIImageOrientationLeft || originalImage.imageOrientation == UIImageOrientationRight);
BOOL b3 = originalImage.imageOrientation == UIImageOrientationLeft;
BOOL b4 = originalImage.imageOrientation == UIImageOrientationRight;
横屏中, 正面照是:UIImageOrientationRight
upsidedown 照片是 UIImageOrientationLeft
//根据给定得图片,从其指定区域截取一张新得图片
-(UIImage *)getImageFromImage:(UIImage *)image rect:(CGRect)rect
{
//开始上下文
UIGraphicsBeginImageContext(rect.size);
CGImageRef imageRef = image.CGImage;
//创建子图像索引
CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, rect);
//获取当前上下文
CGContextRef context = UIGraphicsGetCurrentContext(); //在当前上下文下, 定位为rect下, 画出子图像索引
CGContextDrawImage(context,CGRectMake(, , rect.size.width, rect.size.height), subImageRef); //创建图片对象, 根据图像索引
UIImage *subImage = [[UIImage alloc] initWithCGImage:subImageRef]; //销毁创建的子图像索引,不然会导致内存泄露
CGImageRelease(subImageRef);
//结束上下文
UIGraphicsEndImageContext();
return subImage;
}
被render成为新图片之后 uiimage默认的imageOrientation是正方向(UIImageOrientationUp)
图片方向转换
这几天写个拍照,或者从相册中选择照片,进行剪切,然后分享.结果出现了,剪切后图片颠倒或者旋转90度的问题. 找了很久才发现是忽略imageOrientation这个属性. 以下为解决方法: [cpp] view plaincopy
+ (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, );
transform = CGAffineTransformRotate(transform, M_PI_2);
break; case UIImageOrientationRight:
case UIImageOrientationRightMirrored:
transform = CGAffineTransformTranslate(transform, , 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, );
transform = CGAffineTransformScale(transform, -, );
break; case UIImageOrientationLeftMirrored:
case UIImageOrientationRightMirrored:
transform = CGAffineTransformTranslate(transform, aImage.size.height, );
transform = CGAffineTransformScale(transform, -, );
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), ,
CGImageGetColorSpace(aImage.CGImage),
CGImageGetBitmapInfo(aImage.CGImage));
CGContextConcatCTM(ctx, transform);
switch (aImage.imageOrientation) {
case UIImageOrientationLeft:
case UIImageOrientationLeftMirrored:
case UIImageOrientationRight:
case UIImageOrientationRightMirrored:
// Grr...
CGContextDrawImage(ctx, CGRectMake(,,aImage.size.height,aImage.size.width), aImage.CGImage);
break; default:
CGContextDrawImage(ctx, CGRectMake(,,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;
}
来源:http://blog.csdn.net/iukey/article/details/7308433
使用UIImageView来播放动画.
-(void)viewDidLoad
{
[superviewDidLoad]; self.title=NSLocalizedString(@"ImagesTitle",@"");
//setupourUIImagewithagrouporarrayofimagestoanimate(orinourcaseaslideshow)
self.imageView.animationImages = [NSArrayarrayWithObjects:[UIImageimageNamed:@"scene1.jpg"],[UIImageimageNamed:@"scene2.jpg"],[UIImageimageNamed:@"scene3.jpg"],[UIImageimageNamed:@"scene4.jpg"],[UIImageimageNamed:@"scene5.jpg"], nil ]; imageView.animationDuration=5.0;
[self.imageViewstopAnimating]; //Settheappropriateaccessibilitylabels.
[self.imageViewsetIsAccessibilityElement:YES];
[self.imageViewsetAccessibilityLabel:self.title];
[self.slidersetAccessibilityLabel:NSLocalizedString(@"DurationSlider",@"")];
}
UIImageView 动画 / UIImage 方向的更多相关文章
- 通过cagradientLayer类封装uiimageview动画色度差
#import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger, EcolorDirectionType) { EcolorDirectionUp, / ...
- iOS - UIImageView 动画
1.UIImageView 动画 1.1 播放图片集 播放图片集 @property (nonatomic, strong) UIImageView *playImageView; self.play ...
- UIImageView 动画
1.UIImageView 动画 1.1 播放图片集 @property (nonatomic, strong) UIImageView *playImageView; self.playImageV ...
- UIimageView和UIimage的小区别
UIimageView 用来显示一张图片或者显示一组动画图片 UIimage 不是一个控件,只是一个普通的类,用来生成一张图片,只单纯的生成一张图片,图片只会被加载到内存,如果想要让用户 ...
- UIImageView~动画播放的内存优化
我目前学到的知识,播放动画的步骤就是下面的几个步骤,把照片资源放到数组里面,通过动画animationImage加载数组,设置动画播放的 时间和次数完成播放. 后来通过看一些视频了解到:当需要播放多个 ...
- UIImageView动画
NSMutableArray *arrM = [NSMutableArray array]; // 2.加载所有图片 ; i <= ; i++) { NSString *imageName = ...
- UIImageView动画制作
1.先初始化一个UIImageView的视图窗口 如:anima UIImageView *anima = [UIImageView alloc]initWithFrame(0,0,100,100); ...
- 关于jquery所有动画都有速度和动画的方向(在宽度方向上的动画)?
不只是jquery的 animate 动画, 才有时间的 参数, 实际上, 在所有的动画中, 包括: show/hide/toggle, slideup/slidedown/slidetoggle, ...
- [UE4]判断UI动画播放方向
使用一个变量来记录播放的方向.
随机推荐
- 微信小程序全面实战,架构设计 && 躲坑攻略(小程序入门捷径教程)
最近集中开发了两款微信小程序,分别是好奇心日历(每天一条辞典+一个小投票)和好奇心日报(轻量版),直接上图: Paste_Image.png 本文将结合具体的实战经验,主要介绍微信小程序的基础知识.开 ...
- 年前辞职-WCF入门(6)
前言 昨天早上去医院做入职体检,被告知要预约,本以为是要排队,我连视频都准备好了...结果就回来了.下午去了新公司那边找房子,2了,因为公司提供了班车列表,我既然就只在班车所经过的几个地方找,却遗漏了 ...
- QQ面向对象设计
通讯项目--仿QQ聊天程序 详细设计说明书 一.引言 此项目为验证Jav ...
- 原型图利器 – Mockplus的审阅功能
Mockplus是一款简洁快速的原型图工具 (http://www.mockplus.cn),最近推出了审阅功能. 审阅,旨在解决团队项目原型设计中的沟通和协作的问题. 没有孤立的原型,更没有一次成型 ...
- Andriod开发环境的发展演变
安卓早先只能使用JAVA开发应用程序,现在支持多种编程语言,方便了许多程序员,但主流的应该还是JAVA语言.早先安卓开发经常用到eclipse,但自从google 发布了Android studio后 ...
- Java-transient
transient的作用及使用方法 都知道一个对象只要实现了Serilizable接口,这个对象就可以被序列化,java的这种序列化模式为开发者提供了很多便利,我们可以不必关系具体序列化的过程,只要这 ...
- Java算法-希尔排序
希尔排序的诞生是由于插入排序在处理大规模数组的时候会遇到需要移动太多元素的问题.希尔排序的思想是将一个大的数组“分而治之”,划分为若干个小的数组,以 gap 来划分,比如数组 [1, 2, 3, 4, ...
- 【ZOJ 3897】Candy canes//Fiddlesticks
题 题意 给你一串数,a1...an,从左到右每次让一个数减小c,如果这个数小于c,那就减为0.第n个数减小后,又从第一个开始从左到右.如果这次某个数减小到0,那就改变方向,如果遇到已经是0的,就跳过 ...
- Memory Allocation API In Linux Kernel && Linux Userspace、kmalloc vmalloc Difference、Kernel Large Section Memory Allocation
目录 . 内核态(ring0)内存申请和用户态(ring3)内存申请 . 内核态(ring0)内存申请:kmalloc/kfree.vmalloc/vfree . 用户态(ring3)内存申请:mal ...
- mysql 高级查询
高级查询:1.连接查询select * from Info,Nation #这是两个表名,中间用逗号隔开形成笛卡尔积select * from Info,Nation where Info.natio ...