| 赞 | 0 |
| VIP | |
| 好人卡 | |
| 积分 | 1 |
| 经验 | |
| 最后登录 | 2023-7-14 |
| 在线时间 | 156 小时 |
- 梦石
- 0
- 星屑
- 60
- 在线时间
- 156 小时
- 注册时间
- 2011-12-13
- 回帖
- 127
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 dant 于 2012-3-4 12:19 编辑
使用内存操作
为某个大坑服务
[pre lang="ruby" line="1"]class Bitmap
#--------------------------------------------------------------------------
# ● 传送到内存的API函数
#--------------------------------------------------------------------------
RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
Memcpy_ii = Win32API.new('kernel32.dll','RtlMoveMemory','iii','v')
Malloc = Win32API.new('msvcrt.dll','malloc','i','i')
Free = Win32API.new('msvcrt.dll','free','i','v')
#--------------------------------------------------------------------------
# ● Bitmap地址
#--------------------------------------------------------------------------
# [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
def address
buffer, ad = "rgba", object_id * 2 + 16
RtlMoveMemory_pi.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 8
RtlMoveMemory_pi.call(buffer, ad, 4)
ad = buffer.unpack("L")[0] + 16
RtlMoveMemory_pi.call(buffer, ad, 4)
return buffer.unpack("L")[0]
end
#--------------------------------------------------------------------------
# ● 上下翻转
#--------------------------------------------------------------------------
def reverse!
len = width * height * 4
pBuf = Malloc.call(len)
lenln = width * 4
src = address + len - lenln
dst = pBuf
for i in 0...height
Memcpy_ii.call(dst,src,lenln)
src-=lenln
dst+=lenln
end
Memcpy_ii.call(address,pBuf,len)
Free.call(pBuf)
end
def reverse
newBmp=self.clone
newBmp.reverse!
return newBmp
end
end
[/pre]
|
|