PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Richard Marchessault on January 14, 2013, 05:27:38 PM

Title: FireImage Save to BMP
Post by: Richard Marchessault on January 14, 2013, 05:27:38 PM
How can I save an image loaded into a FireImage control as a BMP file?
Title: Re: FireImage Save to BMP
Post by: Israel Vega Alvarez on January 14, 2013, 08:29:58 PM
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 (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