已经有过的尝试:
GifBitmapDecoder decoder = new GifBitmapDecoder(
new Uri("OH.gif", UriKind.Relative),
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
foreach (BitmapFrame f in decoder.Frames)//for (int i = 0; i < n; ++i )
{
//线程不能更改UI界面部件,所以要用Dispatcher方法
img.Dispatcher.Invoke(new Action(() =>
{
img.Source = f;
}));
byte[] bitPic = new byte[4 * f.PixelWidth * f.PixelHeight];
Int32Rect rect = new Int32Rect(0, 0, f.PixelWidth, f.PixelHeight);
f.CopyPixels(rect, bitPic, f.PixelWidth * 4, 0);
}
在主窗口Image控件img已经能够分帧输出图像,证明BitmapFrame已经有值,但是数组bitPic[]没有得到值。我需要将像素集合存到数组,然后单个像素处理。
GifBitmapDecoder decoder = new GifBitmapDecoder(
new Uri("OH.gif", UriKind.Relative),
BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
foreach (BitmapFrame f in decoder.Frames)//for (int i = 0; i < n; ++i )
{
//线程不能更改UI界面部件,所以要用Dispatcher方法
img.Dispatcher.Invoke(new Action(() =>
{
img.Source = f;
}));
byte[] bitPic = new byte[4 * f.PixelWidth * f.PixelHeight];
Int32Rect rect = new Int32Rect(0, 0, f.PixelWidth, f.PixelHeight);
f.CopyPixels(rect, bitPic, f.PixelWidth * 4, 0);
}
在主窗口Image控件img已经能够分帧输出图像,证明BitmapFrame已经有值,但是数组bitPic[]没有得到值。我需要将像素集合存到数组,然后单个像素处理。