delphi 用API函数抓取屏幕图像


本文整理自网络,侵删。

 procedure screenshot(shot: string);
var
dibH : hBitmap;
bits : pointer;
info : TBITMAPINFO;
width,height : integer;
screenDC,dibDC : hDC;
f : file of byte;
FileHeader : TBITMAPFILEHEADER;
begin
screenDC := getDC(getDeskTopWindow);
dibDC := createCompatibleDC(screenDC);
width := getDeviceCaps(screenDC,HORZRES);
height := getDeviceCaps(screenDC,VERTRES);
info.bmiHeader.biXPelsPerMeter := round(getDeviceCaps(screenDC,LOGPIXELSX)*39.37);
info.bmiHeader.biYPelsPerMeter := round(getDeviceCaps(screenDC,LOGPIXELSY)*39.37);
zeromemory(@info,sizeOf(info));
with info.bmiHeader do
begin
biSize := sizeOf(TBITMAPINFOHEADER);
biWidth := width;
biheight := height;
biplanes := 1;
biBitCount := 24;
biCompression := BI_RGB;
end;
dibH := createDIBSection(dibDC,info,DIB_RGB_COLORS,bits,0,0);
selectObject(dibDC,dibH);
bitblt(
dibDC,
0,0,width,height,
screenDC,
0,0,
SRCCOPY);
releaseDC(getDeskTopWindow,screenDC);
assignFile(f,shot);
reWrite(f);

if width and 3 <> 0 then
width := 4*((width div 4)+1);

with fileHeader do
begin
bfType := ord('B')+(ord('M')shl 8);
bfSize := sizeOf(TBITMAPFILEHEADER)+sizeOf(TBITMAPINFOHEADER)+width*height*3;
bfOffBits := sizeOf(TBITMAPINFOHEADER);
end;

blockWrite(f,fileHeader,sizeOf(TBITMAPFILEHEADER));
blockWrite(f,info.bmiHeader,sizeOf(TBITMAPINFOHEADER));
blockWrite(f,bits^,width*height*3);
closeFile(f);
deleteObject(dibH);
deleteDC(dibDC);
end;

相关阅读 >>

Delphi datasnap双缓存下载文件

Delphi 查看 dll 的输出函数列表

Delphi 一个绘制虚线的非常规函数(常规方法,打印机上绘制不出虚线)

Delphi 网上获取北京时间 tinifile.readsection 方法在 android 下的应用及各种字符编码问题

Delphi版pspterminateprocess驱动源码

windows关机函数exitwindowsex使用大全(适用windows所有操作平台)

Delphi服务程序(service)的调试方法

Delphi 在减少占用资源的情况下,等待msecs毫秒

Delphi获取身份证号码验证码算法

[Delphi]钩子(hook)机制的使用

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...