加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 dant 于 2012-3-4 12:19 编辑
使用内存操作
为某个大坑服务
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
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
|