The dll procedure returns hDC raw image, image width and height.
Then I try to get that image to save to file.
1st I tried with CatchImage:
Code: Select all
GetImage(*hDev, @w, @h, @*imgData) ; get captured image
; [in] h_dev - Object handle
; [out] w - image cols
; [out] h - image rows
; [out] bits - image data
; System.Drawing.Bitmap img = new Bitmap(W, H, W, Imaging.PixelFormat.Format8bppIndexed, hDC)
; System.Drawing.Imaging.ColorPalette gray = img.Palette
Debug h
Debug w
Debug *imgData ;
imgMemSize = w*h
ShowMemoryViewer(*imgData,imgMemSize)
Img = CatchImage(#PB_Any, *imgData, imgMemSize)
Debug Img
If Img > 0
SetGadgetState(ImGad_Prev, ImageID(Img))
EndIf
SaveImage(ImageID(Img), "img.bmp", #PB_ImagePlugin_BMP)
1.
Code: Select all
Structure PB_StructureDataBase
Bitmap.xl
Width.xl
Height.xl
Depth.xl
ColorArray.xl
EndStructure
Declare.xl Hbitmap2PBImage(hbitmap.xl)
Procedure.xl Hbitmap2PBImage(hbitmap.xl)
; - pbImg.xl = Hbitmap2PBImage(hbitmap.xl)
; - Returns pbImg Handle from hBitmap
; - Manually Release hBitmap and pbImg
Protected *idb.PB_StructureDataBase
GetObject_(hbitmap, SizeOf(BITMAP), @bm.BITMAP)
If bm\bmBits
*idb = CreateImage(#PB_Any, bm\bmWidth, bm\bmHeight, bm\bmBitsPixel)
If IsImage(*idb)
DeleteObject_(*idb\Bitmap)
*idb\Bitmap = hbitmap
EndIf
EndIf
ProcedureReturn *idb
EndProcedure
Code: Select all
Structure myBITMAPINFO
bmiHeader.BITMAPINFOHEADER
bmiColors.RGBQUAD[1]
EndStructure
Procedure CopyMemToImage(mem.xl, Img.xl)
Protected bmi.myBITMAPINFO
Protected w.xl, h.xl, hBmp.xl, hDC.xl
w = ImageWidth(Img)
h = ImageHeight(Img)
hBmp = ImageID(Img)
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = w
bmi\bmiHeader\biHeight = -h
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
hDC = StartDrawing( ImageOutput(Img) )
If SetDIBits_(hDC, hBmp, 0, h, mem, bmi, #DIB_RGB_COLORS)
StopDrawing()
ProcedureReturn #True
Else
StopDrawing()
ProcedureReturn #False
EndIf
EndProcedure
Code: Select all
Procedure displayBMP(hDIB)
Define *pDIB.BITMAPINFOHEADER = GlobalLock_(hDIB)
Define bmpFH.BITMAPFILEHEADER
bitCount = *pDIB\biBitCount
clrsUsed = *pDIB\biClrUsed
If clrsUsed = 0 And bitCount <= 8
clrsUsed = 1 << bitCount
EndIf
If *pDIB\biCompression = #BI_RGB
bytesPerRow = (((*pDIB\biWidth * bitCount) + 31) / 32) * 4
*pDIB\biSizeImage = bytesPerRow * *pDIB\biHeight
ElseIf *pDIB\biSizeImage = 0
ProcedureReturn -1
EndIf
With bmpFH
\bfType = $4d42 ;ASCII for 'BM'
\bfReserved1 = 0
\bfReserved2 = 0
\bfOffBits = SizeOf(BITMAPFILEHEADER) +
SizeOf(BITMAPINFOHEADER) +
SizeOf(RGBQUAD) * clrsUsed
\bfSize = \bfOffBits + *pDIB\biSizeImage
EndWith
If bitCount < 24
If clrsUsed = 0 And bitCount <= 8
palletteSize = (1<<bitCount) * 4
EndIf
EndIf
bfhSize = SizeOf(bmpFH)
bmpOffset = bfhSize + *pDIB\biSize + palletteSize
bmpSize = bmpOffset + *pDIB\biSizeImage
If bmpSize <= 0
ProcedureReturn -1
EndIf
*bmpBuffer = AllocateMemory(bmpSize)
CopyMemory(@bmpFH, *bmpBuffer, bfhSize)
CopyMemory(*pDIB, *bmpBuffer + bfhSize, bmpSize - bfhSize)
imgNo = CatchImage(#PB_Any, *bmpBuffer, bmpSize)
; SetGadgetState(#imgGadgetNo, ImageID(imgNo))
GlobalUnlock_(hDIB)
; FreeImage(imgNo)
FreeMemory(*bmpBuffer)
ProcedureReturn imgNo
EndProcedure
After raw image is placed in memory it is handled and displayed by standard C# functions without any dll function calls.
How RAW image is converted to BMP?