赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 8217 |
最后登录 | 2024-9-14 |
在线时间 | 68 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 120
- 在线时间
- 68 小时
- 注册时间
- 2007-12-16
- 帖子
- 75
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
這個優化版
速度快了很多
而且把一些該釋放的釋放掉了
(作截圖存檔請自己找Bitmap的Marshal 找一下就有了)
- #==============================================================================
- # ■ Graphics.snap_to_bitmap 優化2版
- # 原作者:神思
- # 優化者:釣到一隻猴子@_@ ( AAM@_@ )
- #==============================================================================
- #==============================================================================
- # ■ Graphics
- #------------------------------------------------------------------------------
- # 进行有关全体图像处理的模块。
- # RMXP 版的 Graphics.snap_to_bitmap
- #==============================================================================
- 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')
- HWnd = Win32API.new("user32", "GetActiveWindow", nil, 'l').call
- DwCount = (640 * 480 * 4) * 2
- @@lpBits = "\000" * DwCount
- #--------------------------------------------------------------------------
- # ● snap_to_bitmap
- # 将当前画面转换为Bitmap对象
- #--------------------------------------------------------------------------
- def snap_to_bitmap
- width, height = 640,480
- hb = Bitmap.new(width, height)
- rgbs = self.bitmap_data
- len = width * 4
- for y in 0...height
- break if 2*y >= height - 1
- nth1 = y * len
- nth2 = (height - 1 - y) * len
- tStr = rgbs[nth1,len]
- rgbs[nth1, len] = rgbs[nth2, len]
- rgbs[nth2, len] = tStr
- end
- RtlMoveMemory.call(hb.address, rgbs, 640 * 480 * 4)
- return hb
- end
- #--------------------------------------------------------------------------
- # ● bitmap_data
- # 获取当前画面的数据部分```
- # RGB依然是调转过来了`= =``
- #--------------------------------------------------------------------------
- def bitmap_data
- hScrDC = CreateDC.call("DISPLAY", "", "", 0)
- hMemDC = CreateCompatibleDC.call(hScrDC)
- hBitmap = CreateCompatibleBitmap.call(hScrDC, 640, 480)
- hOldBitmap = SelectObject.call(hMemDC, hBitmap)
- BitBlt.call(hMemDC, xsrc, ysrc, 640*2, 480*2, 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
- #==============================================================================
- # ■ Bitmap
- #------------------------------------------------------------------------------
- # 处理影像的类。
- #==============================================================================
- class Bitmap
- RtlMoveMemory = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def address
- # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
- buffer, ad = "xxxx", object_id * 2 + 16
- RtlMoveMemory.call(buffer, ad, 4)
- ad = buffer.unpack("L")[0] + 8
- RtlMoveMemory.call(buffer, ad, 4)
- ad = buffer.unpack("L")[0] + 16
- RtlMoveMemory.call(buffer, ad, 4)
- return buffer.unpack("L")[0]
- end
- end
复制代码 |
|