• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi中一个获得窗口图象的函数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
过程名:    CreateBMPFromWindow
功能:      获得一个句柄为Hwnd的窗口的图象
参数:      Hwnd: 窗体句柄
             PicBitNum: 图象位数(15,16,24,32)
返回值:    TBitmap
function CreateBMPFromWindow(Hwnd: THandle;PicBitNum: Byte): TBitmap;
  
{创建一个空的Bitmap}
  
function CreateDibBMP(Dc: HDC;width,height: Integer): HBITMAP;
  
type
    DibRec 
= record
      bi: BITMAPINFOHEADER;
      ct: 
array[0..255of DWORD;
    
end;
  
var
    Dib: DibRec;
    lpBits: pointer;
    temp: TBitmapInfo;
  
begin
      dib.bi.biSize :
= sizeof(BITMAPINFOHEADER);
      dib.bi.biWidth :
= width;
      dib.bi.biHeight :
= height;
      dib.bi.biBitCount :
= PicBitNum;
      dib.bi.biPlanes :
= 1;
      dib.bi.biCompression :
= 0;
      dib.bi.biSizeImage :
= 0;
      dib.bi.biClrUsed :
= 0

      
if PicBitNum = 15 then
        Dib.bi.biBitCount :
= 16
      
else if PicBitNum = 16 then
      
begin
        Dib.bi.biCompression :
= BI_BITFIELDS;
        dib.ct[
0] := $F800;
        dib.ct[
1] := $07E0;
        dib.ct[
2] := $001F;
      
end;
     Move(dib,temp,SizeOf(dib));
     result :
= CreateDIBSection(Dc,temp,DIB_RGB_COLORS,lpBits,0,0);
  
end;
var
  rc: TRect;
  x,y,cx,cy: integer;
  hdcScreen,hdcMemory: HDC;
begin
    GetWindowRect(hwnd, rc);
    x :
= rc.left;
    y :
= rc.top;
    cx :
= rc.right - rc.left;
    cy :
= rc.bottom - rc.top;
    hdcScreen :
= GetDC(0);
    hdcMemory :
= CreateCompatibleDC(0);
    result :
= TBitmap.Create;
    Result.Handle :
= CreateDibBMP(hdcScreen, cx, cy);
    SelectObject(hdcMemory, result.Handle);
    BitBlt(hdcMemory, 
00, cx, cy, hdcScreen, x, y, SRCCOPY);
    DeleteDC(hdcMemory);
    ReleaseDC(
0, hdcScreen);
end;

 



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi实现文件关联发布时间:2022-07-18
下一篇:
matlab文件操作及读txt文件(fopen,fseek,fread,fclose)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap