大神求助!!!半夜等
这是一段DX代码!!是保存为一个BMP文件!
我不需要保存文件。只需要将它存放在Tbitmap的变量中。或者直接返回tbitmap。。帮忙修改修改呗。。在线等
delphi
function GetBitmapFromScreen(lpFileName: PChar):bool;
var
lpBuf: Pchar;
hBitmap,hOld: windows.HBITMAP ;
hDC,hcDC: windows.HDC;
bb: BITMAP;
b: BITMAPINFO;
hp,fh: THANDLE ;
dwX,dwY: DWORD;
begin
fh := INVALID_HANDLE_VALUE;
//***************
dwX := GetSystemMetrics(SM_CXSCREEN);
dwY := GetSystemMetrics(SM_CYSCREEN);
hDC := GetDC(0);
hcDC:=CreateCompatibleDC(hDC);
hBitmap:=CreateCompatibleBitmap(hDC,dwX,dwY);
hOld :=windows.HBITMAP(SelectObject(hcDC,hBitmap));
BitBlt(hcDC,0, 0,dwX,dwY, hDC, 0, 0, SRCCOPY);
bb.bmWidth:=dwX;
bb.bmHeight :=dwY;
bb.bmPlanes := 1;
bb.bmWidthBytes:=bb.bmWidth*3;
bb.bmBitsPixel:=3;
bb.bmType:=0;
b.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
b.bmiHeader.biWidth:=dwX;
b.bmiHeader.biHeight :=dwY;
b.bmiHeader.biPlanes := 1;
b.bmiHeader.biBitCount :=3*8;
b.bmiHeader.biCompression := BI_RGB;
b.bmiHeader.biSizeImage := 0;
b.bmiHeader.biXPelsPerMeter := 0;
b.bmiHeader.biYPelsPerMeter := 0;
b.bmiHeader.biClrUsed := 0;
b.bmiHeader.biClrImportant := 0;
b.bmiColors[0].rgbBlue:=8;
b.bmiColors[0].rgbGreen:=8;
b.bmiColors[0].rgbRed:=8;
b.bmiColors[0].rgbReserved:=0;
hp:=GetProcessHeap;
lpBuf:=PChar(HeapAlloc(hp,fh,bb.bmHeight*bb.bmWidth*4));
GetDIBits(hcDC,hBitmap,0,dwY,lpBuf,b,DIB_RGB_COLORS);
SaveBitmapToFile(@bb,lpFileName,lpBuf);
ReleaseDC(0,hDC);
DeleteDC(hcDC);
DeleteObject(hBitmap);
DeleteObject(hOld);
HeapFree(hp,0,lpBuf);
Result:=True;
end;
hOld :=windows.HBITMAP(SelectObject(hcDC,hBitmap));
BitBlt(hcDC,0, 0,dwX,dwY, hDC, 0, 0, SRCCOPY);
bb.bmWidth:=dwX;
bb.bmHeight :=dwY;
bb.bmPlanes := 1;
bb.bmWidthBytes:=bb.bmWidth*3;
bb.bmBitsPixel:=3;
bb.bmType:=0;
b.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
b.bmiHeader.biWidth:=dwX;
b.bmiHeader.biHeight :=dwY;
b.bmiHeader.biPlanes := 1;
b.bmiHeader.biBitCount :=3*8;
b.bmiHeader.biCompression := BI_RGB;
b.bmiHeader.biSizeImage := 0;
b.bmiHeader.biXPelsPerMeter := 0;
b.bmiHeader.biYPelsPerMeter := 0;
b.bmiHeader.biClrUsed := 0;
b.bmiHeader.biClrImportant := 0;
b.bmiColors[0].rgbBlue:=8;
b.bmiColors[0].rgbGreen:=8;
b.bmiColors[0].rgbRed:=8;
b.bmiColors[0].rgbReserved:=0;
hp:=GetProcessHeap;
lpBuf:=PChar(HeapAlloc(hp,fh,bb.bmHeight*bb.bmWidth*4));
GetDIBits(hcDC,hBitmap,0,dwY,lpBuf,b,DIB_RGB_COLORS);
//SaveBitmapToFile(@bb,lpFileName,lpBuf);
ReleaseDC(0,hDC);
DeleteDC(hcDC);
//DeleteObject(hBitmap);
DeleteObject(hOld);
HeapFree(hp,0,lpBuf);
Result := dBitmap;
end;