企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 1 gdi绘点流程 设备环境可以在处理非 WM_PAINT 消息时由 Windows 程序获取。调用 GetDC(hwnd) 和 ReleaseDC(hwnd,hdc)。 * 获取设备环境(即 DC)的句柄 hdc表示 GetDC() * 获取点信息(即颜色),这步可以不用 直接在下一步中指定颜色也可 GetPixel() * 对指定点赋值(即颜色) SetPixel() * 释放hdc ReleaseDC() # 2 aardio中代码 ``` import gdi import winex.desktop import console console.open() winform.button.oncommand = function(id,event){ // 实现将桌面的一个矩形区域的图象复制到指定窗口中去 var pcolor=0; for(x=1;50;1){ for(y=1;50;1){ pcolor = gdi.getPixel(x,y,0) //获得桌面指定点颜色 //console.log(pcolor) gdi.setPixel(x+50,y+50,pcolor,winform.custom.hwnd) } } } ``` # 3 aardio 封装代码 API接口: ``` // 获取hdc ::GetDC = u.api("GetDC","ptr(addr hwnd)"); //抓像素颜色 ::GetPixel = g.api("GetPixel","int(ptr hdc,int x,int y)"); //修改像素颜色 ::SetPixel = g.api("SetPixel","int(ptr hdc,int x,int y,int crColor)"); // 释放hdc ::ReleaseDC = u.api("ReleaseDC","bool(addr hwnd,PTR hdc)"); ``` aardio封装:已将获取和释放设备环境的句柄 hdc 一同封装了,不用再考虑这些。 注:hwnd = 0 表示的是桌面窗口的句柄 ``` getPixel = function(x,y,hwnd = 0 ){ var hdc = GetDC(hwnd); if(hdc){ var pix = GetPixel(hdc,x,y); ::ReleaseDC(hwnd,hdc); return pix; } } setPixel = function(x,y,color,hwnd = 0 ){ var hdc = GetDC(hwnd); if(hdc){ var pix = SetPixel(hdc,x,y,color); ::ReleaseDC(hwnd,hdc); return pix; } } ``` ## 运行后的效果 ![](https://img.kancloud.cn/81/94/81940a762d20e610d7669e50dd02bead_426x358.png)