Captures portion of screen to a bmp and stores it in an HDC.
Syntax:hDCBmp = GETBMP(LeftSrc AS INTEGER, _ TopSrc AS INTEGER, _ WidthSrc AS INTEGER, _ HeightSrc AS INTEGER, _ HndlWnd AS HWND) Return Value:
Parameters:
|
If the WidthSrc or HeightSrc argument exceeds the size of the client area of the parent, or if the WidthSrc or HeightSrc argument equals zero, then the client area size is used. This will improve the quality of the resulting bitmap and it provides an easy way to capture the entire client area of the parent HWND.
DIM AS HDC hdc hdc = GETBMP (0, 0, 0, 0, Form1) ' Fetch the entire client area of Form1 SAVEBMP(hdc, "c:\temp\test.bmp")
Saves to file, in .bmp format, an image, either stored in an HDC or, accessible through a HBITMAP Use the GETBMP function to store a bitmap in a HDC.
👉 Please note that SAVEBMP does not handle alpha layer / transparency attributes; therefore, the .bmp produced may not render as expected.
Syntax:SAVEBMP(hDCBmp, FileName AS STRING) Parameters:
|
This example will save a bitmap from an HBITMAP.
DIM AS HBITMAP HndlBmp HndlBmp = BCX_LOADBMP("Source.bmp", 0) SAVEBMP(HndlBmp, "Destination.bmp")
This example will save a bitmap from an HDC.
' **************************************************************** ' GetBmp SaveBmp Demo by Robert Wishlaw 2002-05-28 ' **************************************************************** GUI "GetBmp-SaveBmp" DIM Form1 AS CONTROL DIM Button3 AS CONTROL DIM Button4 AS CONTROL DIM Button5 AS CONTROL DIM Rich1 AS CONTROL DIM Stat1 AS CONTROL DIM Buffer$ DIM Rect AS RECT DIM HDCBmp AS HDC DIM HndlWnd AS HWND DIM retval DIM str1$ MACRO RunEx(lpFile, _ lpParameters, _ nShowCmd) = _ ShellExecute(0, _ "open", _ lpFile, _ lpParameters, _ 0, _ nShowCmd) SUB FORMLOAD CALL LoadBuffer1() '****************************************************************** Form1 = BCX_FORM ("GetBmp SaveBmp" , 0, 0,218,130) Button3 = BCX_BUTTON ("Capture Client" ,Form1,101, 5,10, 50, 15) Button4 = BCX_BUTTON ("Capture Portion",Form1,102, 55,10, 50, 15) Button5 = BCX_BUTTON ("Capture Screen" ,Form1,103,105,10, 50, 15) Rich1 = BCX_RICHEDIT( Buffer$ ,Form1,104, 5,30,200, 60) Stat1 = BCX_STATUS ( "Ready" ,Form1) '******************************************************************* SendMessage(Rich1,EM_SETBKGNDCOLOR,0,0x00f3f3f3) ' Set background color CENTER(Form1) ' Center it! SHOW(Form1) ' Show it! END SUB BEGIN EVENTS SELECT CASE CBMSG '********************** CASE WM_COMMAND '********************** IF CBCTL = 101 THEN ' Capture Client area of a window GetClientRect(Rich1, &Rect) HDCBmp = GETBMP(Rect.left, Rect.top, _ Rect.right - Rect.left, _ Rect.bottom - Rect.top, _ Rich1) SAVEBMP(HDCBmp, "richedit.bmp") 'IMPORTANT ! Release device context resources back to system. retval = DeleteDC(HDCBmp) str1$ = "richedit.bmp" RunEx(str1$, "" , 1) ' Start default paint app END IF IF CBCTL = 102 THEN 'Capture User defined area of a window HDCBmp = GETBMP(10, 58, 360, 54, Rich1) SAVEBMP(HDCBmp, "richedit.bmp") 'IMPORTANT ! Release device context resources back to system. retval = DeleteDC(HDCBmp) str1$ = "richedit.bmp" RunEx(str1$, "" , 1) ' Start default paint app END IF IF CBCTL = 103 THEN ' Capture screen. NULL is HDC for screen HndlWnd = GetDesktopWindow() HDCBmp = GETBMP(0, 0, 300, 200, HndlWnd) SAVEBMP(HDCBmp, "richedit.bmp") 'IMPORTANT ! Release device context resources back to system. retval = DeleteDC(HDCBmp) str1$ = "richedit.bmp" RunEx(str1$, "", 1) ' Start default paint app END IF EXIT FUNCTION '********************** CASE WM_CLOSE '********************** IF MSGBOX("Are you sure?", "Quit Program!", MB_YESNO) = IDYES THEN DestroyWindow(Form1) END IF EXIT FUNCTION END SELECT END EVENTS SUB LoadBuffer1 () Buffer$ = "" Buffer$ = Buffer$ & "{\rtf1\ansi\ansicpg1252\deff0\deflang1033" Buffer$ = Buffer$ & "{\fonttbl" Buffer$ = Buffer$ & "{\f0\froman Times New Roman;}" Buffer$ = Buffer$ & "{\f1\fmodern Lucida Console;}" Buffer$ = Buffer$ & "{\f2\fswiss Arial;}" Buffer$ = Buffer$ & "}" Buffer$ = Buffer$ & "{\colortbl ;" Buffer$ = Buffer$ & "\red192\green000\blue000;" Buffer$ = Buffer$ & "\red000\green000\blue160;" Buffer$ = Buffer$ & "\red255\green255\blue255;" Buffer$ = Buffer$ & "}\qc" Buffer$ = Buffer$ & "\f0\fs72\cf1\b\i BCX \i0\b0\par" Buffer$ = Buffer$ & "\f0\fs64\cf2 GetBmp SaveBmp" Buffer$ = Buffer$ & "}" END SUB