Welcome

首页 / 软件开发 / .NET编程技术 / Windows 8应用实例:WinRT下创建GIF动画(Flipflop)

Windows 8应用实例:WinRT下创建GIF动画(Flipflop)2014-07-03在Windows Store中下载了一个有意思的应用,叫做Flipflop (http://apps.microsoft.com/windows/app/flipflop/99c01512-fe4f-4d1a- 872e-eb9fd6638ff4),该应用允许用户创建翻页式动画效果(Flipbook Animation), 并且可以导出动画为GIF文件。在MSDN看到一篇介绍该项目的技术 文章,分享给大家。

Flipflop项目中,作者使用Windows Imaging Component(WIC)实现创建图片 (MSDN查看Windows 8 WIC新特性),

在项目中引用Windows.Graphics命名空间,在该空间中包含BitmapEncoder类 (MSDN),通过该类可以创建特定的图片编码,例如GifEncoder。

通过代码查看工具,可以看到作者创建一个共享类"GifMaker"实现 动画帧的定义,

using System;using System.Collections.Generic;using System.Runtime.InteropServices.WindowsRuntime;using Windows.Foundation;using Windows.Graphics.Imaging;using Windows.Storage;namespace Utilities{public sealed class GifMaker{readonly List<byte[]> frames = new List<byte[]>();private readonly uint frameWidth;private readonly uint frameHeight;public GifMaker(uint width, uint height){frameWidth = width;frameHeight = height;}public void AppendNewFrame([ReadOnlyArray]byte[] frame){frames.Add(frame);}