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动画播放方向
使用一个变量来记录播放的方向.
随机推荐
- CSS 居中大全(转)
转自这里,收藏备用. <center> 不建议用了. text-align:center 在父容器里水平居中 inline 文字,或 inline 元素 vertical-align:mi ...
- (旧)子数涵数·Flash——路径补间
一.打开flash软件(图为flash8) 二.创建新项目->Flash文档 三.使用椭圆工具,绘制一个圆形图像(快捷键为O,很形象吧) 四.在后面若干帧中插入关键帧,并移动刚刚绘制好的图像的位 ...
- jquery基本方法
jquery的delay sleep 与js的setTime的区别. delay 和sleep推荐不要用,太难用了. click on live delegate bind http://www.jb ...
- “未能加载文件或程序集“EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”
产生原因: 使用nuget管理程序包,同一个解决方案里面有不同版本的Entity Framework,有可能在不同时间安装不同版本的Entity Framework,所以出现这个问题. 解决方案: 1 ...
- javascript继承(四)—prototype属性介绍
js里每一个function都有一个prototype属性,而每一个实例都有constructor属性,并且每一个function的prototype都有一个constructor属性,这个属性会指向 ...
- (好文推荐)一篇文章看懂JavaScript作用域链
闭包和作用域链是JavaScript中比较重要的概念,首先,看看几段简单的代码. 代码1: var name = "stephenchan"; var age = 23; func ...
- 小记:事务(进程 ID 56)与另一个进程被死锁在 锁 | 通信缓冲区 资源上,并且已被选作死锁牺牲品。
今天在做SQL并发UPDATE时遇到一个异常:(代码如下) //Parallel 类可产生并发操作(即多线程) Parallel.ForEach(topics, topic => { //DBH ...
- PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数
一.中文截取:mb_substr() mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处,起始处为0 $l ...
- 《疯狂Java:突破程序员基本功的16课》读书笔记-第一章 数组与内存控制
很早以前就听过李刚老师的疯狂java系列很不错,所以最近找一本拿来拜读,再此做下读书笔记,促进更好的消化. 使用Java数组之前必须先对数组对象进行初始化.当数组的所有元素都被分配了合适的内存空间,并 ...
- Teradata 语句简单优化
Teradata 基本查询语言和SQL server 是一致的.有很小的区别. 功能没有SQL 全面,界面没有SQL 好看~ 1. teradata 里面经常会报一种错误: no enough spo ...