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动画播放方向
使用一个变量来记录播放的方向.
随机推荐
- nginx自学
需要了解的linux的命令: linux的命令:netstat -antnetstat -antp(天假了参数P)ps aux | grep 80kill -9 2985 号进程pkill -9 ht ...
- DOM(二)使用DOM
在了解DOM(文本对象模型)的框架和节点后,最重要的是使用这些节点处理html网页 对于一个DOM节点node,都有一系列的属性和方法可以使用.常用的有下表. 完善:http://www.w3scho ...
- Moqui学习之代码分析mantle priceServices.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- This software is in the pub ...
- PHP函数可变参数列表的具体实现方法介绍
PHP函数可变参数列表可以通过_get_args().func_num_args().func_get_arg()这三个函数来实现.我们下面就对此做了详细的介绍. AD:2014WOT全球软件技术峰会 ...
- iOS7(iPhone4)button不能改变button的title
最近整了个高端的iPhone4测试机,系统是iOS7.1,测出一个问题,两个button,第二个的enable为NO,点击第一个button,第二个的title改变,然而在iPhone4上并不能运行, ...
- 常用JQuery插件
虽然自己也写过插件,但JQuery插件种类的繁多,大多时候,我还是使用别人写好的插件,这些都是我用了同类插件里较为不错的一些,今天就整理一下公开放出来. UI: jquery.HooRay(哈哈,自己 ...
- BZOJ-2002 弹飞绵羊 Link-Cut-Tree (分块)
2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 6801 Solved: 3573 [Submi ...
- 最新版本的DBCP数据源配置
弄了我一下午,把该加的包都加进去了还是没用,后来把DBCP的包打开来看看才发现路径不对.配置如下: <!-- 使用dbcp配置数据源 --> <bean id="dataS ...
- Ubuntu系统启动过程详解
作者:杨硕,华清远见嵌入式学院讲师. 一. Ubuntu的启动流程 ubuntu的启动流程和我们熟知的RedHat的启动方式有所区别. RedHat的启动过程如下图: 这是我们熟知的linux启动流程 ...
- Aop 是面向切面编程,
Aop 是面向切面编程,是在业务代码中可以织入其他公共代码(性能监控等),现在用普通的方法实现AOP http://blog.csdn.net/heyanfeng22/article/details/ ...