FireImage Save to BMP

Started by Richard Marchessault, January 14, 2013, 05:27:38 PM

Previous topic - Next topic

Richard Marchessault

How can I save an image loaded into a FireImage control as a BMP file?
Thanks,
Dick

Israel Vega Alvarez

#1
You can use this code posted by Steve Rosell in PBForum. 

In you button put this code:

CaptureWindow hwnd_FORM1_fireimage1

you can manipulate the file OPEN "C:\IMAGE.BMP"  or adapt it to your needs

http://www.powerbasic.com/support/pbforums/showthread.php?t=14092

Add this SUB:



Sub CaptureWindow(ByVal hWin As Dword)
  Local hDC   As Dword
  Local hMDC  As Dword
  Local hMBmp As Dword
  Local rc    As Rect
  Local bm    As Bitmap
  Local bmi   As BITMAPINFO
  Local bmpFH As BITMAPFILEHEADER
  Local wb    As Dword
  Local hf    As Long
'
  GetWindowRect hWin, rc
'
  hDC = CreateDC("DISPLAY", ByVal %Null, ByVal %Null, ByVal %Null)
  hMDC = CreateCompatibleDC(hDC)
  bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader)
  bmi.bmiHeader.biWidth = (rc.nRight - rc.nLeft)
  bmi.bmiHeader.biHeight = (rc.nBottom - rc.nTop)
  bmi.bmiHeader.biPlanes = 1
  bmi.bmiHeader.biBitCount = 32
  bmi.bmiHeader.biCompression = %BI_RGB
  hMBmp = CreateDIBSection(hMDC, bmi, %DIB_RGB_COLORS, %Null, 0, 0)
'
  SelectObject hMDC, hMBmp
  GetObject hMBmp, SizeOf(bm), bm
  BitBlt(hMDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, rc.nLeft, rc.nTop, %SRCCOPY)
'
  wb = bmi.bmiHeader.biWidth + (bmi.bmiHeader.biWidth Mod 4)
  bmpFH.bfType = CvI("BM")
  bmpFH.bfOffBits = 54
  bmpFH.bfSize = SizeOf(bmpFH) + (wb * bm.bmHeight)

  hf = FreeFile
  Open "C:\IMAGE.bmp" For Output As #hf
  Print #hf, bmpFH; bmi.bmiHeader; PEEK$(bm.bmBits, bm.bmWidthBytes * bm.bmHeight);
  Close #hf
'
  DeleteDC(hDC)
  DeleteDC(hMDC)
  DeleteObject(hMBmp)
End Sub