赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 8217 |
最后登录 | 2024-9-14 |
在线时间 | 68 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 120
- 在线时间
- 68 小时
- 注册时间
- 2007-12-16
- 帖子
- 75
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
同步發表於RMXP原创技术发布区
這東西向 照相手機的"行動條碼"
- #==============================================================================
- # RM_Bar_code By 釣到一隻猴子@_@ ( AAM@_@ )
- =begin
- #------------------------------------------------------------------------------
- 使用方法
- rmbc = RM_Bar_code.new(text[, size]) # text 為原文字(Stirng類物件)
- # size為條碼大小(size * size的正方形)
- # 以原文字生成RM_Bar_code
- rmbc = RM_Bar_code.new(bitmap) # bitmap 為條碼影像(Bitmap類物件)
- # 以條碼影像生成RM_Bar_code
- rmbc.make_bar_code(text[, size])
- # 同RM_Bar_code.new(text[, size]) 但僅可用於RM_Bar_code類物件
- rmbc.load_bar_code(bitmap)
- # 同RM_Bar_code.new(bitmap) 但僅可用於RM_Bar_code類物件
- rmbc.text
- # 取得原文字(Stirng類物件)
- rmbc.bitmap
- # 取得條碼影像(Bitmap類物件)
- #------------------------------------------------------------------------------
- =end
- #==============================================================================
- #==============================================================================
- # ■ RM_Bar_code
- #------------------------------------------------------------------------------
- # 。
- #==============================================================================
- class RM_Bar_code
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- Black = [0,0,0,255].pack("c*")
- Gray = [128,128,128,255].pack("c*")
- White = [255,255,255,255].pack("c*")
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def initialize(data, size = 32)
- @bitmap = nil
- @text = ""
- if data.is_a?(String)
- make_bar_code(data, size)
- elsif data.is_a?(Bitmap)
- load_bar_code(data)
- # else
- end
- end
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def make_bar_code(text, size = 32)
- @text = text
- @bitmap = Bitmap.new(size, size)
- b = @text.unpack("b*")[0]
- b += "2" * (size ** 2 - b.size) if b.size < size ** 2
- b.gsub!("0") {Black}
- b.gsub!("1") {White}
- b.gsub!("2") {Gray}
- @bitmap.save(b)
- end
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def load_bar_code(bitmap)
- @bitmap = bitmap
- b = @bitmap.load
- b.gsub!(Gray) {""}
- b.gsub!(Black) {"0"}
- b.gsub!(White) {"1"}
- @text = [b].pack("b*")
- end
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def text
- @text
- end
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def bitmap
- @bitmap
- end
- end
- #==============================================================================
- # ■ Bitmap
- #------------------------------------------------------------------------------
- # 处理影像的类。
- #==============================================================================
- class Bitmap
- RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
- RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def load
- data = "rgba" * width * height
- RtlMoveMemory_pi.call(data, address, data.length)
- return data
- end
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def save(str)
- RtlMoveMemory_ip.call(address, str, width * height * 4)
- return self
- end
- #--------------------------------------------------------------------------
- # ●
- #--------------------------------------------------------------------------
- def address
- # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
- buffer, ad = "xxxx", 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
复制代码 |
|