Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

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

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 04-04-2006   #1 (permalink)
MueMeister
Guest


 

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
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem getting exception info from unmanaged C++ akash .NET General 0 06-11-2008 02:22 PM
Dispose Unmanaged resources Curious .NET General 2 03-24-2008 11:01 AM
Implementing Unmanaged Interface in C# Saad .NET General 0 03-13-2008 01:04 AM
Problem creating an BitmapSource from an HBitmap in threaded code Shaun Bedingfield .NET General 0 03-05-2008 07:32 AM
BitmapSource Disposal/cleanup King Adrock Avalon 2 07-25-2006 11:25 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51