![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Having spent years using Visual C++, I'm a relevent newbie to .NET./ I'm fairly comfortable with teh new programming environment, but the one area that I constantly struggle with is calling legacy VC DLL's (straight Dll's, not extension Dlls). Usingwww.PInvoke.netI usually find an equivalent example and learn from that, but one specific item has defeated me. In the legacy DLL I have a function :- BOOL GetLatestImage( BITMAPINFO *pInfo, BYTE *pPixelBuffer ) ; It returns the format of the image in pInfo and copies raw pixel data in pPixelBuffer. (pPixelBuffer can be NULL if all's you want is pInfo). So, how do I call this function from .NET so that I can get the image into an 'Image' or 'Bitmap' class ? As the function call may be used frequently (lets say 100 times per second for the sake of argument) I'm also looking for efficiency if possible. Thanks in advance. TTFN, Jon |
#3
| |||
| |||
|
|
[Part of useful code section snipped] static class code { public static void foo() { BitmapInfo info = new BitmapInfo(); byte[] array = new byte[100]; // allocate corect size info.rgbInfo = new RGBQUAD[256]; // allocate correct size UnsafeNativeMethods.GetLatestImage(info, array); // note on return info.rgbInfo will have size of 1 element. Can't help that with no sizeConst } } } |
|
OK. Before this question can be answered, you need to answer the following: Do you have to allocate the color table array at the end of BITMAPINFO before you can make this call? In addition, how do you know the size you need to allocate for pixelBuffer? how do you know the size of the color table array to allocate? |
#4
| |||
| |||
|
|
"Doug Semler" wrote: [Part of useful code section snipped] static class code { public static void foo() { BitmapInfo info = new BitmapInfo(); byte[] array = new byte[100]; // allocate corect size info.rgbInfo = new RGBQUAD[256]; // allocate correct size UnsafeNativeMethods.GetLatestImage(info, array); // note on return info.rgbInfo will have size of 1 element. Can't help that with no sizeConst } } } Thanks for that ! OK. Before this question can be answered, you need to answer the following: Do you have to allocate the color table array at the end of BITMAPINFO before you can make this call? In addition, how do you know the size you need to allocate for pixelBuffer? how do you know the size of the color table array to allocate? Yes, the caller is expected to calc the buffer size from the bitmapinfo - not very OOP I grant you, but that's legacy stuff for you :-( I do however have the luxury of knowing the image will be either 24 or 32 bit, so no colour table to worry about. |
|
The last missing link for me is how to get the byte array into the Bitmap ? The intention would be to create the Bitmap and Byte[] objects the first time they are needed, and only destroy them and build new ones if the image size changes (which will be a rare occurence). |
|
Finally, to me, the operations are a bit "black box". What is happening under the hood ? For example, worst case would be having already copied image into byte array, the "managing" process did a copy and then there was another copy to get it into the bitmap object. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |