Unity分解Gif为List<Texture>
2018-03-21 22:29
627 查看
1、将 Editor\Data\Mono\lib\mono\2.0\System.Drawing.dll
复制到 Assets\Library\System.Drawing.dll
2、应用以下代码using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using UnityEngine;
public class GifUtil
{
/// <summary>
/// 分解GIF
/// </summary>
public static List<Texture2D> GetTextures(string path)
{
List<Texture2D> textures = new List<Texture2D>();
Image gif = Image.FromFile(path);
if (gif == null)
return textures;
FrameDimension dimension = new FrameDimension(gif.FrameDimensionsList[0]);
for (int index = 0; index < gif.GetFrameCount(dimension); index++)
{
gif.SelectActiveFrame(dimension, index);
MemoryStream stream = new MemoryStream();
gif.Save(stream, ImageFormat.Png);
Texture2D texture = new Texture2D(gif.Width, gif.Height);
byte[] bytes = stream.ToArray();
texture.LoadImage(stream.ToArray());
//texture.LoadRawTextureData(bytes);
stream.Close();
textures.Add(texture);
}
return textures;
}
}
代码比较简单,就不写注释了,粘上应该0报错,报错请留言
复制到 Assets\Library\System.Drawing.dll
2、应用以下代码using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using UnityEngine;
public class GifUtil
{
/// <summary>
/// 分解GIF
/// </summary>
public static List<Texture2D> GetTextures(string path)
{
List<Texture2D> textures = new List<Texture2D>();
Image gif = Image.FromFile(path);
if (gif == null)
return textures;
FrameDimension dimension = new FrameDimension(gif.FrameDimensionsList[0]);
for (int index = 0; index < gif.GetFrameCount(dimension); index++)
{
gif.SelectActiveFrame(dimension, index);
MemoryStream stream = new MemoryStream();
gif.Save(stream, ImageFormat.Png);
Texture2D texture = new Texture2D(gif.Width, gif.Height);
byte[] bytes = stream.ToArray();
texture.LoadImage(stream.ToArray());
//texture.LoadRawTextureData(bytes);
stream.Close();
textures.Add(texture);
}
return textures;
}
}
代码比较简单,就不写注释了,粘上应该0报错,报错请留言
相关文章推荐
- Unity中JsonUtility对List<T>和Dictionary<Key,Value>的序列化
- 【unity实用技能】List<T>类几个常用的函数
- 在Unity序列化List<>
- Java: 分解List<HashMap<String, String>>
- Map类型数据的使用和如何输出Map<String, List<>>类型的数据
- 俄罗斯水手 [C#] 对List<T>取交集、连集及差集
- List<List<E>> list = new ArrayList<ArrayList<E>>()报错的解决方法
- C# List<T>的详细用法
- unity3D ShaderLab <五>漫反射光照改善技巧之使用2D ramp texture来创建一个假的BRDF(双向反射分布函数)
- Unity手游之路<三> 基于Unity+Java的聊天室源码
- List<Object>根据Object里的2个属性排序
- C#List<string>和string[]之间的相互转换
- 打印出 List<Product> 中的内容
- LNK2019: 无法解析的外部符号 "public: void __thiscall List<int>::add(int const &)" (?add@?$List@H@@QAEXABH@Z),
- Jfinal中DB返回List<Record>并将其按Record某字段分类,后转换为Map并返回前端
- public static <T> List<T> asList(T... a) 原型是怎么回事?
- List<T>的使用
- winform DataGridView绑定List<T>类型数据
- TreeList<下>
- List<Map<String,Object>>使用Java代码遍历以获取String,Object的值