赞 | 0 |
VIP | 8 |
好人卡 | 27 |
积分 | 55 |
经验 | 41413 |
最后登录 | 2012-10-21 |
在线时间 | 833 小时 |
Lv4.逐梦者 弓箭手?剑兰
- 梦石
- 0
- 星屑
- 5464
- 在线时间
- 833 小时
- 注册时间
- 2010-11-17
- 帖子
- 1140
|
2楼
楼主 |
发表于 2011-5-7 14:55:32
|
只看该作者
良性连帖,请勿扣分
Bitmap的Marshal(包括里面的Font)
特色只是可以连Bitmap的font都可以一起Marshal。- #==============================================================================
- # ■ Bitmap的Marshal by 柳之一(原创) + 一箭烂(添加 dump Font类)
- #==============================================================================
- class Bitmap
- #--------------------------------------------------------------------------
- # ● 传送到内存的API函数
- #--------------------------------------------------------------------------
- RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
- RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
- #--------------------------------------------------------------------------
- # ● 存放
- #--------------------------------------------------------------------------
- def _dump(limit)
- data = "rgba" * width * height
- RtlMoveMemory_pi.call(data, address, data.length)
- font = Marshal.dump(self.font)
- data = Zlib::Deflate.deflate(data)
- [data.size, width, height, data, font].pack("LLLa#{data.size}a*")
- end
- #--------------------------------------------------------------------------
- # ● 读取
- #--------------------------------------------------------------------------
- def self._load(obj)
- size, w, h, zdata, font = obj.unpack("LLLa#{obj.unpack("L")}a*")
- b = self.new(w, h)
- RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4)
- b.font = Marshal.load(font)
- return b
- end
- #--------------------------------------------------------------------------
- # ● 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
- end
复制代码 |
|