views:

74

answers:

1

Hi to all,

I am excited to be a part of the forum :)
my first post !

I am posting this so that many can benefit from it.

My question: what is the fastest/performance approach to send large managed Bitmap object to unmanaged/native function ?

I will be using C++/CLI, (VS 2008, .NET 3.5) for that purpose

One Approach: pin_ptr
use pin_ptr instead of copying (Marshalling) pixel data of Bitmap object from managed to unmanaged for increasing performance / speed

Other Approach (specifically for Bitmap would be): unmanaged WPF Imaging Component.
If this is a better approach it would be great if someone could throw some light on it (some code) or give some pointers in this direction

Thanks

A: 

It isn't really clear what "send to native function" might mean. You shouldn't need much more than Bitmap::GetHbitmap() to get a HBITMAP handle. If you need a pointer to the raw pixel data then use Bitmap::LockBits().

Hans Passant
by "send to native function", I mean, passing parameter to unmanaged function or a function in a native dll.
vijiboy
Thanks for your answer. You said Bitmap::GetHbitmap(): will it not create another bitmap; copying large bitmaps can degrade performance. and Bitmap::LockBits() will again allocate a temporary buffer and copy the pixel data, which is again 'copying of data' hampering performance as I feel...
vijiboy
Well, ask for the right pixel format so it can use the pixel data as-is without creating a new one. Did you try this?
Hans Passant
As I tried, it seems, `Bitmap::LockBits()` does allocate memory for full bitmap data, even if the pixel format is same as the Bitmap being locked, even if you specify to lock full bitmap rectangle or portion of it. But the memory just allocated (`BitmapData->Scan0`) seems to be 'pinned'. I think that is actually native memory and not 'pinned' managed memory...
vijiboy
thanks! for your suggestion. I am going to use your suggestion `Bitmap::LockBits()` for urgency but need to find more faster approach sooner...
vijiboy