Michael Phillips, Jr.
9/11/2007 4:48:00 PM
> 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@gmail.com> wrote in message
news:1189527579.653624.255620@d55g2000hsg.googlegroups.com...
> On Sep 11, 12:06 pm, "Michael Phillips, Jr."
> <mphillip...@nospam.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?
>