Click here to Skip to main content
12,945,066 members (56,547 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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:
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++){
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); 
             ,intptr,Stride*bitmapSource->PixelHeight, Stride);
for(long j = 0;j<bitmapSource->PixelHeight*bitmapSource->PixelWidth;j++)
//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 true images on a form window by this codes:
System::Windows::Window^ mainWindow;
mainWindow = gcnew System::Windows::Window();
               mainWindow->Title = "GIF Imaging Sample";
               //ScrollViewer^ mySV = gcnew ScrollViewer();
array<System::Byte>^ pixels = gcnew array<System::Byte>(bitmapSource->PixelHeight * Stride);
bitmapSource = decoder->Frames[0];
Image^ myImage = gcnew Image();
myImage->Source = bitmapSource;
myImage->Stretch = Stretch::None;
myImage->Margin = System::Windows::Thickness(0);
StackPanel^ myStackPanel = gcnew StackPanel();
myStackPanel->Orientation = Orientation::Vertical;
myStackPanel->VerticalAlignment = VerticalAlignment::Stretch;
myStackPanel->HorizontalAlignment = HorizontalAlignment::Stretch;
// mySV->Content = myStackPanel;
mainWindow->Content = myStackPanel;//mySV;
mainWindow->Width = bitmapSource->PixelHeight;
mainWindow->Height = bitmapSource->PixelHeight;
//mainWindow->ResizeMode = System::Windows::ResizeMode::NoResize;

when i change
bitmapSource = decoder->Frames[0];

bitmapSource = decoder->Frames[1];

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.
Posted 18-Dec-12 21:05pm
Updated 19-Dec-12 19:45pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,781
CHill60 3,135
Maciej Los 2,443
Jochen Arndt 1,910
ppolymorphe 1,765

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 20 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100