| 赞 | 0  | 
 
| VIP | 8 | 
 
| 好人卡 | 27 | 
 
| 积分 | 66 | 
 
| 经验 | 41413 | 
 
| 最后登录 | 2012-10-21 | 
 
| 在线时间 | 833 小时 | 
 
 
 
 
 
Lv4.逐梦者 弓箭手?剑兰 
	- 梦石
 - 0 
 
        - 星屑
 - 6559 
 
        - 在线时间
 - 833 小时
 
        - 注册时间
 - 2010-11-17
 
        - 帖子
 - 1140
 
 
 
 | 
	
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员  
 
x
 
 本帖最后由 一箭烂YiJL 于 2011-5-28 17:45 编辑  
 
0.序 
这是将Bitmap 类(挺)高速的保存为bmp档案。因为之前想用柳之一的《Bitmap高速Marshal》和保存png结合, 
但其实是上下倒置,而且png格式每行都要插进"0",获取每点的颜色值比起用数组"搞定"上下倒置和插"0"要快! 
今天我研究了一下bmp档案,bmp格式是上下倒置,而且不用插"0",所以将拿到的数据直接写入bmp的颜色值数据流中。 
然而这样比png的每点扫要快得多,VX的屏幕载图储存bmp,fps不会降! 
 
1.脚本 
脚本如下(XP/VX),柳之一的《Bitmap高速Marshal》已经不是那个样了(而且不能Marshal= =): 
 
- #==============================================================================
 
 - # ■ BmpWriter             by 一箭烂YiJL (获取颜色值部分 by 柳之一)
 
 - #------------------------------------------------------------------------------
 
 - #  使用手册:
 
 - #
 
 - #     BmpWriter.write(bitmap, [name[, path]])
 
 - #       bitmap    : 位图
 
 - #       name      : 保存文件名
 
 - #       path      : 保存路径
 
 - #
 
 - #     自动创建路径!
 
 - #==============================================================================
 
  
- module BmpWriter
 
 -   #--------------------------------------------------------------------------
 
 -   # ● 传送到内存的API函数
 
 -   #--------------------------------------------------------------------------
 
 -   RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
 
 -   #--------------------------------------------------------------------------
 
 -   # ● 制作bmp档案
 
 -   #--------------------------------------------------------------------------
 
 -   def self.write(bitmap, name = "Bitmap.bmp", path = "Pictures/")
 
 -     ## 先要工作
 
 -     Dir.mkdir(path) unless FileTest.directory?(path)
 
 -     length = bitmap.width * bitmap.height
 
 -     file = File.open(path + name, "wb")
 
 -     
 
 -     ## BitmapFileHeader
 
 -     size = 54 + length * 4
 
 -     chunk = "BM" + [size, 0, 54].pack("L*")
 
 -     file.write(chunk)
 
 -     
 
 -     ## BitmapInfoHeader
 
 -     chunk = [40, bitmap.width, bitmap.height, 1, 32, 0, 0, 0xEC4, 0xEC4, 256, 0].pack("L3S2L*")
 
 -     file.write(chunk)
 
 -     
 
 -     ## Byte
 
 -     data = "rgba" * bitmap.width * bitmap.height
 
 -     RtlMoveMemory_pi.call(data, bitmap.address, data.length)
 
 -     chunk = data
 
 -     file.write(chunk)
 
 -     
 
 -     file.close
 
 -   end
 
 - end
 
  
- class Bitmap
 
 -   #--------------------------------------------------------------------------
 
 -   # ● 传送到内存的API函数
 
 -   #--------------------------------------------------------------------------
 
 -   RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
 
 -   #--------------------------------------------------------------------------
 
 -   # ● 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
 
  复制代码 
2.范例 
只有VX的:
 
BmpWriter(VX).zip
(280.85 KB, 下载次数: 248)
 
在任何场景按F8就可以载图,保存在 Pictures/Bitmap.bmp 
没有XP的是因为XP还要找XP的Graphics.snap_to_bitmap,如果真的很想要的话就回帖伸手吧~ 
 |   
 
评分
- 
查看全部评分
 
 
 
 
 
 |