private string filename = "8.gif";
private List<WriteableBitmap> list = new List<WriteableBitmap>();
async void hf_FileCompeted(int code, object sender)
{
Windows.Storage.StorageFolder localFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("image", Windows.Storage.CreationCollisionOption.OpenIfExists);
IStorageFile fileinto = await localFolder.GetFileAsync(filename);
IRandomAccessStream ias = await fileinto.OpenReadAsync();
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(BitmapDecoder.GifDecoderId, ias);
System.Diagnostics.Debug.WriteLine("总的帧数:" + decoder.FrameCount.ToString());
Print(decoder.PixelHeight + ":" + decoder.PixelWidth);
for (int k = 0; k < (int)decoder.FrameCount; k++)
{
// 获取第一帧
BitmapFrame frame = await decoder.GetFrameAsync((uint)k);
// 获取像素数据
PixelDataProvider pixprd = await frame.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, new BitmapTransform(), ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage);
Print(frame.DpiX+":"+frame.DpiY+":"+frame.OrientedPixelHeight+":"+frame.OrientedPixelWidth+":"+frame.PixelHeight+":"+frame.PixelWidth);
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
// 创建新的位图对象
WriteableBitmap wb = new WriteableBitmap((int)frame.PixelWidth, (int)frame.PixelHeight);
byte[] data = pixprd.DetachPixelData();
data.CopyTo(wb.PixelBuffer);
wb.Invalidate();
list.Add(wb);
}
);
}
time = new System.Threading.Timer(new TimerCallback(timerReport), null, 300, 0);
}
private void Print(string str)
{
System.Diagnostics.Debug.WriteLine(str);
}
System.Threading.Timer time;
private int kindex = 0;
/// <summary>
/// 计时器检查链接和心跳包
/// </summary>
/// <param name="obj"></param>
private async void timerReport(object obj)
{
try
{
time.Change(300, 0);
kindex++;
if (kindex >= 8)
{
kindex = 0;
}
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
img.Source = list[kindex];
});
}
catch
{
}
}