Delphi image intercept programming example (2)

xiaoxiao2021-03-06  110

(4) Creating a unit file for grabbing image SCRNCPT

UNIT SCRNCPT;

Interface

uses windows, forms, controls, classes, Graphics; function CaptureScreenRect (ARect: TRect): TBitmap; function CaptureScreen: TBitmap; function CaptureClientImage (Control: TControl): TBitmap; function CaptureControlImage (Control: TControl): TBitmap; function CaptureWindowImage (Wnd : HWnd: Tbitmap;

IMPLEMentation

Function CaptureScreenRect (all): Tbitmap; var screendc: HDC; // Device Description Table Handle Begin Result: = Tbitmap.create; With Result, Arect Do Begin Width: = Right-LEFT; Height: = Bottom-Top; ScreenDC: = getDC (0); // Get a window's device descriptor handle, 0 Parameters Return to the screen window Detection Table Try // Bool Bitblt (HDCDest, NXDest, Nydest, Nwidth, NHEight, HDCSRC, NXSRC, NYSRC, DWROP) // Copy the bitmap from the source device description table HDCSRC to the target device description table hdcdest, / / ​​raster operand DWROP Specifies the combination of source diagrams Bitblt (Canvas.Handle, 0, 0, Width, Height, ScreenDC, LEFT, TOP, SRCCPY; Finally ReleaseDC (0, ScreenDC); End; end;

// Full screen graph Function CaptureScreen: Tbitmap; Begin with Screen Do Result: = CaptureScreenRect (RECT (0, 0, Width, Height);

// Caught the client area of ​​a form or control Function CaptureClientImage (Control: tControl): Tbitmap; Begin //Control.Clientorigin is the top left corner of the control client area. X, Y is Clientorigin's variable with Control, Control.Clientorigin Do Result: = CaptureScreenRect (Bounds (X, Y, ClientWidth, ClientHeight); END;

// Caught a whole form or control Function CaptureControlImage: Tbitmap; begin with control do if parent = nil dam without a parent form, according to its location, directly capture Result: = CaptureScreenRect (Bounds (LEFT, TOP, WIDTH, Height) ELSE // has a parent form, transform it into a screen coordinate, and then capture with perent.clienttoscreen (Point (Left, TOP)) do result: = CaptureScreenRect (Bounds X, Y, width, height);

/ / Depending on the form handle, the Function CaptureWindowImage (WND: HWnd): Tbitmap; Var r: TRECT; Begin getWindowRect (WND, R); // Put the window coordinates specified by the window handle in TREENRECT (R) (r) = CaptureScreenRect End;

转载请注明原文地址:https://www.9cbs.com/read-97529.html

New Post(0)