HighTechTalks DotNet Forums  

Converting GDI+ Bitmap from unmanaged code to managed code

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Converting GDI+ Bitmap from unmanaged code to managed code in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Cartoper
 
Posts: n/a

Default Converting GDI+ Bitmap from unmanaged code to managed code - 09-11-2007 , 11:53 AM






I have a very simple (I think) question: How do I convert a unmanaged
GDI+ bitmap into a managed GDI+ Image? The code is C++ CLI (.Net
2.0). There is another option, the Bitmap is being generated by
calling it's function UnlockBits() that takes a unmanaged
Gdiplus::BitmapData structure. Is it easier/safer to convert the
unmanaged Gdiplus::BitmapData structure and pass that into a managed
Bitmap object's UnlockBits() method?


Reply With Quote
  #2  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Converting GDI+ Bitmap from unmanaged code to managed code - 09-11-2007 , 12:06 PM






Quote:
I have a very simple (I think) question: How do I convert a unmanaged
GDI+ bitmap into a managed GDI+ Image? The code is C++ CLI (.Net
2.0). There is another option, the Bitmap is being generated by
calling it's function UnlockBits() that takes a unmanaged
Gdiplus::BitmapData structure. Is it easier/safer to convert the
unmanaged Gdiplus::BitmapData structure and pass that into a managed
Bitmap object's UnlockBits() method?
There are many ways to Marshal a gdiplus bitmap between managed and
unmanaged code.

Here are a few methods:
1) You may use GetHBITMAP() to pass a handle to a bitmap.
2) You may use a stream to represent the bitmap.
3) You may use a global memory pointer to a packed DIB(i.e.,
BITMAPINFOHEADER, ColorTable, bits).
4) You may use a IPictureDisp interface.

Choice #1 is the easiest to implement.




Reply With Quote
  #3  
Old   
Cartoper
 
Posts: n/a

Default Re: Converting GDI+ Bitmap from unmanaged code to managed code - 09-11-2007 , 12:19 PM



On Sep 11, 12:06 pm, "Michael Phillips, Jr."
<mphillip... (AT) nospam (DOT) jun0.c0m> wrote:

Quote:
There are many ways to Marshal a gdiplus bitmap between managed and
unmanaged code.

Here are a few methods:
1) You may use GetHBITMAP() to pass a handle to a bitmap.
2) You may use a stream to represent the bitmap.
3) You may use a global memory pointer to a packed DIB(i.e.,
BITMAPINFOHEADER, ColorTable, bits).
4) You may use a IPictureDisp interface.

Choice #1 is the easiest to implement.
I major concern is not ease, but speed. The unmanaged code is
manipulating the data in the unmanaged BitmapData.Scan0 to generate
the image for display. When using the LockBits() call, the
ImageLockModeUserInputBuf flag is being set. Is it possible to simply
cast the unmanaged BitmapData to a managed BitmapData?



Reply With Quote
  #4  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Converting GDI+ Bitmap from unmanaged code to managed code - 09-11-2007 , 12:47 PM



Quote:
I major concern is not ease, but speed. The unmanaged code is
manipulating the data in the unmanaged BitmapData.Scan0 to generate
the image for display. When using the LockBits() call, the
ImageLockModeUserInputBuf flag is being set. Is it possible to simply
cast the unmanaged BitmapData to a managed BitmapData?
No. LockBits provides a copy of the bitmap's memory for the rectangular
region passed.

When the lock is released the memory copy is committed to the image.

You can use GCHandle.Alloc to pin the memory for the bitmap when it is
created or
you can use CreateDIBSection to create your bitmap.

The pointer to the DIB's memory can be passed back and forth between managed
and unmanaged memory.

There is no protection offered. Reading and writing occur at your peril.

"Cartoper" <cartoper (AT) gmail (DOT) com> wrote

Quote:
On Sep 11, 12:06 pm, "Michael Phillips, Jr."
mphillip... (AT) nospam (DOT) jun0.c0m> wrote:

There are many ways to Marshal a gdiplus bitmap between managed and
unmanaged code.

Here are a few methods:
1) You may use GetHBITMAP() to pass a handle to a bitmap.
2) You may use a stream to represent the bitmap.
3) You may use a global memory pointer to a packed DIB(i.e.,
BITMAPINFOHEADER, ColorTable, bits).
4) You may use a IPictureDisp interface.

Choice #1 is the easiest to implement.

I major concern is not ease, but speed. The unmanaged code is
manipulating the data in the unmanaged BitmapData.Scan0 to generate
the image for display. When using the LockBits() call, the
ImageLockModeUserInputBuf flag is being set. Is it possible to simply
cast the unmanaged BitmapData to a managed BitmapData?




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.