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动态图上一览无余!当然界面一样打动人心,腾出手点赞的同时!记得另存哟:) 作者 ...
随机推荐
- 基于Tcp协议的简单Socket通信实例(JAVA)
好久没写博客了,前段时间忙于做项目,耽误了些时间,今天开始继续写起~ 今天来讲下关于Socket通信的简单应用,关于什么是Socket以及一些网络编程的基础,这里就不提了,只记录最简单易懂实用的东西. ...
- 基础006_pg109_IP-Xfft
作者:桂. 时间:2018-05-09 07:20:48 链接:http://www.cnblogs.com/xingshansi/p/9012232.html 前言 简要记录xilinx FFT的 ...
- springboot集成redis缓存
1.pom.xml增加redis缓存起步依赖(spring-boot-starter-parent包含许多starter版本) <dependency> <groupId>or ...
- 推荐几个Windows工具软件: ASuite - 便携的程序启动器
主页: http://asuite.sourceforge.net 下载: http://sourceforge.net/projects/asuite/ ASuite is a lightweigh ...
- 蓝牙mesh介绍
了解一下关于蓝牙Mesh的知识. 蓝牙mesh网络使用,并且依赖于低功耗蓝牙(BLE).低功耗蓝牙技术是蓝牙mesh使用的无线通信协议栈. 蓝牙BR / EDR能够实现一台设备到另一台设备的连接和通信 ...
- CentOS最小化安装(一)
一.配置网络 切记记得配置DNS,否则Ping不通 在目录中进行网络配置文件的查找: /etc/sysconfig/network-scripts/ 1 1 /etc/sysconfig/net ...
- 和我一起学Effective Java之泛型
泛型 不要在新代码中使用原始类型 泛型(generic):声明中具有一个或多个类型参数 原始类型(raw type):不带任何实际类型参数的泛型名称 格式: 类或接口的名称 < 对应于泛型形式类 ...
- react-router 4.3 js实现跳转
import React, {Component} from 'react'; import { NavLink,Link } from "react-router-dom"; i ...
- [Converge] Weight Initialiser
From: http://www.cnblogs.com/denny402/p/6932956.html [, ] fully connected w = tf.Variable(tf.truncat ...
- 给 Advice 传递参数
参数绑定是在下面这个方法中做的:org.springframework.aop.aspectj.AbstractAspectJAdvice#invokeAdviceMethod(JoinPoint j ...