views:

82

answers:

2

Hello Sir/Madam,

I have created the BitmapSources using the following code.

Assume iFrameCount is 10.

for(int iIndex = 0; iIndex < iFrameCount; iIndex++) 

{

//Reading Bytes

this.BitmapSources.Add(


BitmapSource.Create(iWidth, iHeight, dpi, dpi, PixelFormats.Rgb24, null, bytes, stride)); 

}

And

using(MemoryStream MemStream = new MemoryStream()) 

{

System.Windows.Controls.

Image oWindowsImage = new System.Windows.Controls.Image();

BitmapEncoder bitMapEncoder = new GifBitmapEncoder(); 

for (int iIndex = 0; iIndex < this.BitmapSources.Count; iIndex++) 

bitMapEncoder.Frames.Add(BitmapFrame.Create(this.BitmapSources[iIndex])); 

bitMapEncoder.Save(MemStream);

}



BitmapImage bitmapImage = new BitmapImage(); 

bitmapImage.BeginInit();

bitmapImage.StreamSource = new MemoryStream(MemStream.ToArray()); 

bitmapImage.CreateOptions = BitmapCreateOptions.PreservePixelFormat; 

bitmapImage.CacheOption = BitmapCacheOption.Default; 

bitmapImage.EndInit();

MemStream.Close();

oWindowsImage.Source = bitmapImage;

But in source it shows with BitmapImage. But i need with BitmapFrame

bitmapFrame = oWindowsImage.Source as BitmapFrame; 

int framesCount = bitmapFrame.Decoder.Frames.Count;

In the second line shows bitmapFrame shows as null. Anybody help me how do i will get the BitmapFrames using oWindowsImage.source

Thanks & Advance.

Britto

A: 

Use,

BitmapFrame.Create(image)

Instead of,

bitmapFrame = oWindowsImage.Source as BitmapFrame

Hope this would help a bit. If I come across any more solid examples, I will let you know…

Happy coding :-)

Sam
A: