Mega Code Archive

 
Categories / Delphi / System
 

Herhangi bir wincontrol veya tüm ekran nasil bitmap olarak alinir

function GetDcAsBitmap(DC: HDC; Bitmap: TBitmap; W, H: Cardinal): Boolean; var hdcCompatible: HDC; hbmScreen: HBitmap; begin Result := False; if DC = 0 then Exit; hdcCompatible := CreateCompatibleDC(DC); hbmScreen := CreateCompatibleBitmap(DC, W, H); if (hbmScreen = 0) then Exit; if (SelectObject(hdcCompatible, hbmScreen)=0) then Exit; if not(BitBlt(hdcCompatible, 0,0, W, H, DC, 0,0, SRCCOPY)) then Exit; Bitmap.Handle := HbmScreen; Bitmap.Dormant; Result := True; end; function GetScreenAsBitmap(Bitmap: TBitmap): Boolean; var ScreenDC: HDC; begin ScreenDC := CreateDC('DISPLAY', NIL, NIL, NIL); Result := GetDCAsBitmap(ScreenDC, Bitmap, GetDeviceCaps(ScreenDC, HORZRES), GetDeviceCaps(ScreenDC, VERTRES) ); end; function GetWindowAsBitmap(const WindowName: string; Bitmap: TBitmap): Boolean; var Wnd: HWnd; Rect: TRect; begin Wnd := FindWindow(nil, PChar(WindowName)); GetWindowRect(Wnd, Rect); Result := GetDCAsBitmap(GetWindowDC(Wnd), Bitmap, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top); end; function GetWindowAsBitmap(Wnd: HWnd; Bitmap: TBitmap): Boolean; var Rect: TRect; begin GetWindowRect(Wnd, Rect); Result := GetDCAsBitmap(GetWindowDC(Wnd), Bitmap, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top); end; // Kullanimi: {Button1 yüzeyini resim olarak al} GetWindowAsBitmap(Button1.Handle, Image1.Picture.Bitmap); {Tüm ekrani resim olarak al} GetScreenAsBitmap(Image1.Picture.Bitmap);