Gif动态图UIImage
#pragma mark 动态图生成
-(UIImage *)getAnimatedGIFWithData:(NSString *)path
{
NSData *data = [NSData dataWithContentsOfFile:path];
if (!data)
{
return nil;
} CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL); size_t count = CGImageSourceGetCount(source); UIImage *animatedImage; if (count <= )
{
animatedImage = [[UIImage alloc] initWithData:data];
}
else
{
NSMutableArray *images = [NSMutableArray array]; NSTimeInterval duration = 0.0f; for (size_t i = ; i < count; i++)
{
CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL); duration += [self frameDurationAtIndex:i source:source]; [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; CGImageRelease(image);
} if (!duration)
{
duration = (1.0f/10.0f)*count;
} animatedImage = [UIImage animatedImageWithImages:images duration:duration];
} CFRelease(source); return animatedImage;
}
-(float)frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source
{
float frameDuration = 0.1f;
CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime];
if (delayTimeUnclampedProp)
{
frameDuration = [delayTimeUnclampedProp floatValue];
}
else
{ NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime];
if (delayTimeProp)
{
frameDuration = [delayTimeProp floatValue];
}
} // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
// We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
// a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082>
// for more information. if (frameDuration < 0.011f)
{
frameDuration = 0.100f;
} CFRelease(cfFrameProperties);
return frameDuration;
}
Gif动态图UIImage的更多相关文章
- iOS 播放gif动态图的方式探讨
原文链接:http://my.oschina.net/u/2340880/blog/608560 摘要iOS中没有现成的接口来展示gif动态图,但可以通过其他的方式来处理gif图的展示.iOS中播放g ...
- IOS-加载动态图(gif)
// // BowenView.h // IOS_0302_下拉刷新 // // Created by ma c on 16/3/2. // Copyright © 2016年 博文科技. All r ...
- Wpf 中使用gif格式的动态图
第一种方法:使用winform插件 <WindowsFormsHost xmlns:wf="clr-namespace:System.Windows.Forms;assembly=S ...
- 在sublime text 中的Emmet快捷键动态图演示
Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度,比如下面的演示: ...
- HighChartS cpu利用率动态图(Java版)
来源:http://www.cnblogs.com/haifg/p/3217699.html 最近项目需要监控服务器cpu的利用率,并做成动态图.在网上查找了一些资料,最终选择了HighChart ...
- GIMP也疯狂之动态图的制作(四)
本篇文章为gimp制作动态图的第四篇.在之前的基础上简单的拓展了下思路.就能做出蛮实用的动态图.本文将介绍两个动态图.第一个为在一张静态图上添加动态图,第二个图为修改部分渐变. 效果: 素材: 其实, ...
- GIMP也疯狂之动态图的制作(三)
Note:本篇文章内容为linux下利用gimp和其它工具组合完成截取制作GIF图的一种实现,制作更为灵活,但并不方便,如果不需要那么高的定制性,并追求方便高效.可以使用类似QQ影音之类的软件,自带截 ...
- iOS开发中在UIWebView中添加Gif动态图
开发是一件很有趣的事,偶尔在程序中添加一些小东西,会给你的应用增色不少.比如,当你的某些功能暂时还不准备上线时,可以先一个放展示Gif动态图的UIWebView上去,既可以告诉用户APP以后会有的功能 ...
- 那些过目不忘的无线端交互设计(DRIBBBLE GIF动态图)
Dribbble精选:Dribbble上令人惊叹的无线端交互设计!来自全球牛人们的奇思妙想,新颖动人的交互在这一张张GIF动态图上一览无余!当然界面一样打动人心,腾出手点赞的同时!记得另存哟:) 作者 ...
随机推荐
- 【Android】Android输入子系统
成鹏致远 | lcw.cnblogs.com | 2013-10-25 Linux输入子系统回顾 1:为什么要回顾linux输入子系统?这个问题后面自然就知道了 1.linux输入子系统设备是基于平台 ...
- js绝对地址图片转换成base64的方法
//将图片转换成base64 function getBase64Image(url, callback){ var canvas = document.createElement('canvas') ...
- MXNET:多层感知机
从零开始 前面了解了多层感知机的原理,我们来实现一个多层感知机. # -*- coding: utf-8 -*- from mxnet import init from mxnet import nd ...
- 完美解决"Encountered an NTFS Volume with a logfile ..."
完美解决Ghost镜像文件时出现"Encountered an NTFS Volume with a logfile that has not been flushed(536)" ...
- c# 调用非托管c++dll 参数问题(转)
在C#中调用C(C++)类的DLL的时候,有时候C的接口函数包含很多参数,而且有的时候这些参数有可能是个结构体,而且有可能是结构体指针,那么在C#到底该如何安全的调用这样的DLL接口函数呢?本文将详细 ...
- Java如何拆分正则表达式和字符串?
在Java编程中,如何拆分正则表达式和字符串? 以下示例演示如何使用regex.Pattern类的Pattern.compile()方法和patternname.split()方法拆分正则表达式. p ...
- Socket 相关资料(随笔)
由于项目上的 http 请求量较大,项目上性能跟不上.于是考虑把 短连接的 http 换成 长连接的tcp 形式 试试效果. 先 研究了一下 长连接方式.就是要用到 socket 方面的知识. pac ...
- mysql数据库建立的数据库在哪个文件夹?
一般在安装目录下的data文件夹下,或者在C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\dat ...
- Python 函数(默认参数)
默认参数 设置默认参数时,有两点需要注意:一是必选参数在前,默认参数在后,否则python的解释器会报错二是当函数有多个参数时,把变化大的参数放前面,变化小的放后面,变化小的参数就可以作为默认参数 d ...
- iOS开发之--cocopods相关问题及解决方法
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default 解决办法:删除工程中的 ...