I am working with COM Interface of a software, OMICRON MPD 600 to be particular. I would like to take a screenshot using the provided methods however it returns the image as DIB populated inside byte array.
How can use this byte array to save this screenshot as an image. I would prefer DIB to Bitmap conversion but actually anything that would allow me to save it as an image is acceptable.
I have a VBA Code that accomplished this task using:
Step 1: CopyMemory
Step 2: GetDC
Step 3: CreateCompatibleDC
Step 4: CreateCompatibleBitmap
Step 5: SelectObject
Step 6: SetDIBits
Step 7: OleCreatePictureIndirect
However When I tried doing this using C# I get stuck first step where I extract BitmapInfoHeader from the byte array. I am able to extract he values but these values seem incorrect.
What I have tried:
int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(BITMAPINFOHEADER));
Debug.Print("Size of BitMapInfoHeader: " + size + "");
GCHandle pinned = GCHandle.Alloc(l, GCHandleType.Pinned);
IntPtr lPtr = pinned.AddrOfPinnedObject();
Debug.Print("Byte Array Lenght: " + l.Length + "");
BITMAPINFOHEADER bim = (BITMAPINFOHEADER)Marshal.PtrToStructure(lPtr, typeof(BITMAPINFOHEADER));
Above C# code Gives me:
Byte Array Lenght: 897860
biWidth after: -256
biHeight after: 511
biSize after: 256
biSizeImage after: 3005743104
biBitCount after: 0
While a working VBA Code produces:
Byte Array Length: 897832
biBitCount: 32
biClrImportant: 0
biClrUsed: 0
biCompression: 0
biHeight: 448
biPlanes: 1
biSize: 40
biSizeImage: 0
biWidth: 501
biXPelsPerMeter: 3110