设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2760|回复: 2
打印 上一主题 下一主题

[已经解决] 如何获取当前画面

[复制链接]

Lv2.观梦者

梦石
0
星屑
615
在线时间
84 小时
注册时间
2012-8-12
帖子
178
跳转到指定楼层
1
发表于 2019-1-28 10:54:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
va有Graphics.snap_to_bitmap
那xp里如何获取?

Lv3.寻梦者

梦石
0
星屑
3670
在线时间
357 小时
注册时间
2018-9-4
帖子
272
2
发表于 2019-1-28 11:06:48 | 只看该作者
本帖最后由 Mono_kyrin 于 2019-1-28 11:12 编辑

Zeus81大的XP,VX,VXace通用Bitmap输出脚本,用法见注释。
简单来说就是用win32API给XP写了个Graphics.snap_to_bitmap,但是增加了几个额外新用法,可以塞入保存文档或者直接保存为文件。
RUBY 代码复制
  1. # Bitmap Export v5.4 for XP, VX and VXace by Zeus81
  2. # Free for commercial use
  3. # Licence : [url]http://creativecommons.org/licenses/by/4.0/[/url]
  4. # Contact : [email protected]
  5. # How to Use :
  6. #   - exporting bitmap :
  7. #       bitmap.export(filename)
  8. #    or bitmap.save(filename)
  9. #
  10. #   - serialize bitmap :
  11. #       open(filename, 'wb') {|file| Marshal.dump(bitmap, file)}
  12. #       bitmap = open(filename, 'rb') {|file| Marshal.load(file)}
  13. #   or
  14. #       save_data(bitmap, filename)
  15. #       bitmap = load_data(filename)
  16. #
  17. #  - snapshot :
  18. #      Graphics.export(filename)
  19. #   or Graphics.save(filename)
  20. #   or Graphics.snapshot(filename)
  21. #   Here filename is optional, and will be replaced by datetime if omitted.
  22.  
  23. $imported ||= {}
  24. $imported[:Zeus_Bitmap_Export] = __FILE__
  25.  
  26. def xp?() false end; alias vx? xp?; alias vxace? xp?
  27. RUBY_VERSION == '1.8.1' ? defined?(Hangup) ?
  28. def xp?() true  end : def vx?() true  end : def vxace?() true  end
  29.  
  30. class String
  31.   alias getbyte  []
  32.   alias setbyte  []=
  33.   alias bytesize size
  34. end unless vxace?
  35.  
  36. class Font
  37.   def marshal_dump()     end
  38.   def marshal_load(dump) end
  39. end
  40.  
  41. class Bitmap
  42.   RtlMoveMemory = Win32API.new('kernel32', 'RtlMoveMemory', 'ppi', 'i')
  43.   def last_row_address
  44.     return 0 if disposed?
  45.     RtlMoveMemory.call(buf=[0].pack('L'), __id__*2+16, 4)
  46.     RtlMoveMemory.call(buf, buf.unpack('L')[0]+8 , 4)
  47.     RtlMoveMemory.call(buf, buf.unpack('L')[0]+16, 4)
  48.     buf.unpack('L')[0]
  49.   end
  50.   def bytesize
  51.     width * height * 4
  52.   end
  53.   def get_data
  54.     data = [].pack('x') * bytesize
  55.     RtlMoveMemory.call(data, last_row_address, data.bytesize)
  56.     data
  57.   end
  58.   def set_data(data)
  59.     RtlMoveMemory.call(last_row_address, data, data.bytesize)
  60.   end
  61.   def get_data_ptr
  62.     data = String.new
  63.     RtlMoveMemory.call(data.__id__*2, [vxace? ? 0x6005 : 0x2007].pack('L'), 4)
  64.     RtlMoveMemory.call(data.__id__*2+8, [bytesize,last_row_address].pack('L2'), 8)
  65.     def data.free() RtlMoveMemory.call(__id__*2, String.new, 16) end
  66.     return data unless block_given?
  67.     yield data ensure data.free
  68.   end
  69.   def _dump(level)
  70.     get_data_ptr do |data|
  71.       dump = Marshal.dump([width, height, Zlib::Deflate.deflate(data, 9)])
  72.       dump.force_encoding('UTF-8') if vxace?
  73.       dump
  74.     end
  75.   end
  76.   def self._load(dump)
  77.     width, height, data = *Marshal.load(dump)
  78.     data.replace(Zlib::Inflate.inflate(data))
  79.     bitmap = new(width, height)
  80.     bitmap.set_data(data)
  81.     bitmap
  82.   end
  83.   def export(filename)
  84.     case format=File.extname(filename)
  85.     when '.bmp'; export_bmp(filename)
  86.     when '.png'; export_png(filename)
  87.     when ''    ; export_png("#{filename}.png")
  88.     else         print("Export format '#{format}' not supported.")
  89.     end
  90.   end
  91.   alias save export
  92.   def export_bmp(filename)
  93.     get_data_ptr do |data|
  94.       File.open(filename, 'wb') do |file|
  95.         file.write(['BM',data.bytesize+54,0,54,40,width,height,
  96.                     1,32,0,data.bytesize,0,0,0,0].pack('a2L6S2L6'))
  97.         file.write(data)
  98.       end
  99.     end
  100.   end
  101.   def export_png(filename)
  102.     data, i = get_data, 0
  103.     if vxace?
  104.       (0).step(data.bytesize-4, 4) do |i|
  105.         byte2 = data.getbyte(i)
  106.         data.setbyte(i, data.getbyte(i+2))
  107.         data.setbyte(i+2, byte2)
  108.       end
  109.     else
  110.       (0).step(data.bytesize-4, 4) do |i|
  111.         data[i,3] = data[i,3].reverse!
  112.       end
  113.     end
  114.     deflate = Zlib::Deflate.new(9)
  115.       null_char, w4 = [].pack('x'), width*4
  116.       (data.bytesize-w4).step(0, -w4) {|i| deflate << null_char << data[i,w4]}
  117.       data.replace(deflate.finish)
  118.     deflate.close
  119.     dir = "Save/"
  120.     File.open(dir + filename, 'wb') do |file|
  121.       def file.write_chunk(chunk)
  122.         write([chunk.bytesize-4].pack('N'))
  123.         write(chunk)
  124.         write([Zlib.crc32(chunk)].pack('N'))
  125.       end
  126.       file.write("\211PNG\r\n\32\n")
  127.       file.write_chunk(['IHDR',width,height,8,6,0,0,0].pack('a4N2C5'))
  128.       file.write_chunk(data.insert(0, 'IDAT'))
  129.       file.write_chunk('IEND')
  130.     end
  131.   end
  132. end
  133.  
  134. module Graphics
  135.   if xp?
  136.     FindWindow             = Win32API.new('user32', 'FindWindow'            , 'pp'       , 'i')
  137.     GetDC                  = Win32API.new('user32', 'GetDC'                 , 'i'        , 'i')
  138.     ReleaseDC              = Win32API.new('user32', 'ReleaseDC'             , 'ii'       , 'i')
  139.     BitBlt                 = Win32API.new('gdi32' , 'BitBlt'                , 'iiiiiiiii', 'i')
  140.     CreateCompatibleBitmap = Win32API.new('gdi32' , 'CreateCompatibleBitmap', 'iii'      , 'i')
  141.     CreateCompatibleDC     = Win32API.new('gdi32' , 'CreateCompatibleDC'    , 'i'        , 'i')
  142.     DeleteDC               = Win32API.new('gdi32' , 'DeleteDC'              , 'i'        , 'i')
  143.     DeleteObject           = Win32API.new('gdi32' , 'DeleteObject'          , 'i'        , 'i')
  144.     GetDIBits              = Win32API.new('gdi32' , 'GetDIBits'             , 'iiiiipi'  , 'i')
  145.     SelectObject           = Win32API.new('gdi32' , 'SelectObject'          , 'ii'       , 'i')
  146.     def self.snap_to_bitmap
  147.       bitmap  = Bitmap.new(width, height)
  148.       info    = [40,width,height,1,32,0,0,0,0,0,0].pack('LllSSLLllLL')
  149.       hDC     = GetDC.call(hwnd)
  150.       bmp_hDC = CreateCompatibleDC.call(hDC)
  151.       bmp_hBM = CreateCompatibleBitmap.call(hDC, width, height)
  152.       bmp_obj = SelectObject.call(bmp_hDC, bmp_hBM)
  153.       BitBlt.call(bmp_hDC, 0, 0, width, height, hDC, 0, 0, 0xCC0020)
  154.       GetDIBits.call(bmp_hDC, bmp_hBM, 0, height, bitmap.last_row_address, info, 0)
  155.       SelectObject.call(bmp_hDC, bmp_obj)
  156.       DeleteObject.call(bmp_hBM)
  157.       DeleteDC.call(bmp_hDC)
  158.       ReleaseDC.call(hwnd, hDC)
  159.       bitmap
  160.     end
  161.   end
  162.   class << self
  163.     def hwnd() @hwnd ||= FindWindow.call('RGSS Player', nil) end
  164.     def width()  640 end unless method_defined?(:width)
  165.     def height() 480 end unless method_defined?(:height)
  166.     def export(filename=Time.now.strftime("snapshot %Y-%m-%d %Hh%Mm%Ss #{frame_count}"))
  167.       bitmap = snap_to_bitmap
  168.       bitmap.export(filename)
  169.       bitmap.dispose
  170.     end
  171.     alias save     export
  172.     alias snapshot export
  173.   end
  174. end

评分

参与人数 1星屑 +50 +1 收起 理由
RyanBern + 50 + 1 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
615
在线时间
84 小时
注册时间
2012-8-12
帖子
178
3
 楼主| 发表于 2019-1-28 11:14:01 | 只看该作者
Mono_kyrin 发表于 2019-1-28 09:06
Zeus81大的XP,VX,VXace通用Bitmap输出脚本,用法见注释。
简单来说就是用win32API给XP写了个Graphics.snap_ ...

多谢,很实用
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-20 13:14

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表