| 赞 | 3 |
| VIP | |
| 好人卡 | |
| 积分 | 31 |
| 经验 | |
| 最后登录 | 2026-9-11 |
| 在线时间 | 441 小时 |
- 梦石
- 0
- 星屑
- 3053
- 在线时间
- 441 小时
- 注册时间
- 2014-11-21
- 回帖
- 103
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 hy2000 于 2020-10-29 23:32 编辑
如题,现在找到的截图脚本似乎都只能截取游戏窗口内的图片,因为游戏内容需要,我想找一个能截取整个电脑屏幕内容或者其一部分的
找到一个古代截图脚本是从这方面入手的,但我试了一下有各种谜之bug,应该是配套的dll本身就有问题()
问一下有没有什么好的思路实现这一点
更新:找到了一个能用的古代截图脚本,修改之后可以用于截取全屏(其中Extra是我自己写的调api的一些方法,get_reso为获取分辨率)
全屏可以正常截取,但要截取其中较小一部分时就会出现问题,有时会截不出来,检测发现在起始0,0,设定范围2倍的区域外截到都是透明,不知道是哪里有问题……
虽然可以靠全屏截图后切割的办法,但效率比较低,会卡上2-3秒,希望还是能实现部分截图
或者有没有效率更高的办法()
二度更新:懂了,应该是原本其中width*2, height*2的设置有误,应当设置为全屏幕。
那么现在能用了,但是效率还是有点低,不知道有无效率更高的做法
- class << Graphics
- CreateDC = Win32API.new("gdi32", "CreateDC", "pppl", "l")
- CreateCompatibleBitmap = Win32API.new("gdi32", "CreateCompatibleBitmap", "lll", "l")
- CreateCompatibleDC = Win32API.new("gdi32", "CreateCompatibleDC", "l", "l")
- SelectObject = Win32API.new("gdi32", "SelectObject", "ll", "l")
- BitBlt = Win32API.new("gdi32", "BitBlt", "lllllllll", "l")
- GetBitmapBits = Win32API.new("gdi32", "GetBitmapBits", "llp", "l")
- ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
- DeleteDC = Win32API.new("gdi32", "DeleteDC", "l", "l")
- DeleteObject = Win32API.new("gdi32", "DeleteObject", "l", "l")
- SRCCOPY = 0xCC0020
- RtlMoveMemory = Win32API.new("kernel32", "RtlMoveMemory", "ipi", "i")
- RtlMoveMemory_pi = Win32API.new("kernel32", "RtlMoveMemory", "pii", "i")
- HWnd = Win32API.new("user32", "GetActiveWindow", nil, 'l').call
- DwCount = (1600 * 800 * 4)# * 2
- @@lpBits = "\000" * DwCount
-
- #---------------------------------------------------------------------------#
- # snap_to_bitmap #
- #---------------------------------------------------------------------------#
- def snap_to_bitmap2()
- xy = Extra.get_reso #获取分辨率
- width = xy[0]
- height = xy[1]
- hb = Bitmap.new(width, height)
- rgbs = self.bitmap_data(0,0,width,height)
- RtlMoveMemory.call(hb.address, rgbs, width * height * 4)
- hb.export("test")
- return hb
- end
- #---------------------------------------------------------------------------#
- # bitmap_data #
- #---------------------------------------------------------------------------#
- def bitmap_data(s_w,s_h,width,height)
- hScrDC = Win32API.new("User32.dll","GetDC",["L"],"L").call(Win32API.new("User32.dll","GetDesktopWindow",[],"L").call())
- hMemDC = CreateCompatibleDC.call(hScrDC)
- hBitmap = CreateCompatibleBitmap.call(hScrDC, width, height)
- hOldBitmap = SelectObject.call(hMemDC, hBitmap)
- win_pos = "\0\0\0\0\0\0\0\0"
- ScreenToClient.call(HWnd, win_pos)
- win_pos = win_pos.unpack("LL")
- xy = Extra.get_reso
- BitBlt.call(hMemDC, s_w, s_h, xy[0], xy[1], hScrDC, 0, 0, SRCCOPY)
- hBitmap2 = SelectObject.call(hMemDC, hOldBitmap)
- GetBitmapBits.call(hBitmap2, DwCount, @@lpBits)
- # 释放所有东西
- DeleteDC.call(hScrDC)
- DeleteDC.call(hMemDC)
- DeleteObject.call(hBitmap)
- DeleteObject.call(hOldBitmap)
- DeleteObject.call(hBitmap2)
- return @@lpBits
- end
- #---------------------------------------------------------------------------#
- # 用户窗口的位置 #
- #---------------------------------------------------------------------------#
- def xsrc
- return self.point[0]
- end
- #---------------------------------------------------------------------------#
- # 用户窗口的位置 #
- #---------------------------------------------------------------------------#
- def ysrc
- return self.point[1]
- end
- #---------------------------------------------------------------------------#
- # 那个点 #
- #---------------------------------------------------------------------------#
- def point
- point = [0,0].pack("LL")
- ScreenToClient.call(HWnd, point)
- return point.unpack("LL")
- end
- end
复制代码 |
|