Gifdecoder,BitmapSource and System.Windows.Controls::Image in mfc
hi.
first of all sorry for my bad english.
i need make a CBitmap or a streamdata from a System.Windows.Controls::Image(rendered out put)in a SDI mfc application (supporting \clr).
here is my codes:
Code:
using namespace System;
using namespace System::IO;
using namespace System::Collections::Generic;
using namespace System::Windows;
using namespace System::Windows::Controls;
using namespace System::Windows::Media;
using namespace System::Windows::Media::Imaging;
using namespace System::Threading;
using namespace System::Security;
bool CGifdecoder::Decoder()
{
UINT Stride;
unsigned short *res;
unsigned short Buff[ROW * COLUMN];
BitmapSource^ bitmapSource ;
String ^ str = gcnew String(Files[m_Current].Filepath);
// Open a Stream and decode a GIF image
Stream^ imageStreamSource = gcnew FileStream(str, FileMode::Open, FileAccess::Read, FileShare::Read);
GifBitmapDecoder^ decoder = gcnew GifBitmapDecoder(imageStreamSource, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
GifInfo[m_Current].Frames = decoder->Frames->Count;
for(int i = 0;i < GifInfo[m_Current].Frames;i++){
Init_ReadDecodedBits();
bitmapSource = decoder->Frames[i];
bpp = bitmapSource->Format.BitsPerPixel;
Stride = (UINT)(bitmapSource->PixelWidth*(bitmapSource->Format.BitsPerPixel / 8) + 3) & (~3);//bitmapSource->PixelWidth * ((bitmapSource->Format.BitsPerPixel + 7) / 8);
res = new unsigned short[bitmapSource->PixelHeight*bitmapSource->PixelWidth];
IntPtr intptr = IntPtr(res);
bitmapSource->CopyPixels(System::Windows::Int32Rect::Empty
,intptr,Stride*bitmapSource->PixelHeight, Stride);
for(long j = 0;j<bitmapSource->PixelHeight*bitmapSource->PixelWidth;j++)
Buff[j]=ReadParseData(bpp,res);
//here i got unrendered codes from bitmapSource
delete res;
}
}
by this codes i can read datastream from bitmapSource but in this way somthing goes wrong in most of GIF animations.
after debug i found out i need 3 more things too decode a gif animation - (x,y) position and size of each frame and disposal method for each one - finally i just found a way to draw tru images on a form window by this codes:
frame[1] has drawn perfectly on window(i think some how Image class takes care about - (x,y) position and size of each frame and disposal method for each one ),so im wonder if how can i make a CBitmap or a data stream from System.Windows.Controls::Image class to use in mfc app.
best regards.
Re: Gifdecoder,BitmapSource and System.Windows.Controls::Image in mfc
Originally Posted by d Rasool
hi.
You're in the wrong forum. This forum is for non-Managed, traditional, C++ using the Visual C++ compiler. Your code is using Managed C++, which is an extension and is off-topic here.
In other words, the code you posted here is gibberish when it comes to what is discussed in this forum (for example, those "^" symbols are totally alien to the C++ language in the context being used in your code).
Please post in the Managed C++ forum as that forum deals with Managed C++ and .NET programming.
Bookmarks