首页 > 代码库 > 用API函数抓取屏幕图像
用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;
用API函数抓取屏幕图像
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。