Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to put unmanaged CBitmap*->GetBitmapBits() into an BitmapSource-derivedclass

 
 
Old 04-04-2006   #1 (permalink)
MueMeister


 
 

How to put unmanaged CBitmap*->GetBitmapBits() into an BitmapSource-derivedclass

Hi all,

I know there are some discussions about getting byte[] from BitmapSource
and how to put byte[] into an BitmapSource through MemoryStream. I tried
a lot of this stuff and I dont't come far. My scenario is living in
C++/CLI and I want to put data from a CBitmap* (from CImageList e.g.)
into a BitmapSource object like BitmapImage for example. To achieve this
I tried the following ways:

1) I tried to use the
BitmapImage::Create( ... , System::IntPtr(pBuffer), ... ) method,
where buffer is a byte field. If I do this the app is crashing during
render-process with InvalidOperationException - "Object must be
initialized before operation can be performed"
Maybe some parameter is corrupt but Create is done!

2) I tried to use the approach from this newsgroup - posted in the very
past. BitmapImage.StreamSource is longing for a stream. I provide a
UnmanagedStreamSource initialized with the buffer from
CBitmap::GetBitmapBits(..). This working until I call
BitmapSource.EndInit(). There I get the following exception:
NotSupportedExcpetion "No codec found that can decode the specefic
file." Since this is raw bitmap data I cannot understand why there is
something to be decoded?! For what is the BitmapImage.SourceStream
lokking for? An encoded in memory buffer?!

3) I tried to use
System::Windows::Interop::Imaging::CreateBitmapSourceFromHBitmap, too.
without success. (If this would work, how does this method realize its
task?)

I really get frustrated with this Imaging stuff since there are NULL
information on the internet or in the newsgroups.

Please give me a hint how to perform such a scenario. Come on, I cannot
believe that I'm the only one with this task - there have to be some
examples approaches on the desks in Redmond?!

Thanks You so much.
Chris :-)

My System SpecsSystem Spec
Old 04-04-2006   #2 (permalink)
Chris


 
 

RE: How to put unmanaged CBitmap*->GetBitmapBits() into an BitmapSourc

.... 15 minutes after the post I got approach 3 to work correctly. There were
some problems concerning the the palette parameter. As a result of this I
tried to cancel the previous post but without success (as You can see).
Anyway do You have a sample for approach 1 or 2 out there?

Thank You so much!
Chris :-)

"MueMeister" wrote:

> Hi all,
>
> I know there are some discussions about getting byte[] from BitmapSource
> and how to put byte[] into an BitmapSource through MemoryStream. I tried
> a lot of this stuff and I dont't come far. My scenario is living in
> C++/CLI and I want to put data from a CBitmap* (from CImageList e.g.)
> into a BitmapSource object like BitmapImage for example. To achieve this
> I tried the following ways:
>
> 1) I tried to use the
> BitmapImage::Create( ... , System::IntPtr(pBuffer), ... ) method,
> where buffer is a byte field. If I do this the app is crashing during
> render-process with InvalidOperationException - "Object must be
> initialized before operation can be performed"
> Maybe some parameter is corrupt but Create is done!
>
> 2) I tried to use the approach from this newsgroup - posted in the very
> past. BitmapImage.StreamSource is longing for a stream. I provide a
> UnmanagedStreamSource initialized with the buffer from
> CBitmap::GetBitmapBits(..). This working until I call
> BitmapSource.EndInit(). There I get the following exception:
> NotSupportedExcpetion "No codec found that can decode the specefic
> file." Since this is raw bitmap data I cannot understand why there is
> something to be decoded?! For what is the BitmapImage.SourceStream
> lokking for? An encoded in memory buffer?!
>
> 3) I tried to use
> System::Windows::Interop::Imaging::CreateBitmapSourceFromHBitmap, too.
> without success. (If this would work, how does this method realize its
> task?)
>
> I really get frustrated with this Imaging stuff since there are NULL
> information on the internet or in the newsgroups.
>
> Please give me a hint how to perform such a scenario. Come on, I cannot
> believe that I'm the only one with this task - there have to be some
> examples approaches on the desks in Redmond?!
>
> Thanks You so much.
> Chris :-)
>

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Problem getting exception info from unmanaged C++ .NET General
Dispose Unmanaged resources .NET General
Implementing Unmanaged Interface in C# .NET General
Problem creating an BitmapSource from an HBitmap in threaded code .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46