| 赞 | 3  | 
 
| VIP | 0 | 
 
| 好人卡 | 2 | 
 
| 积分 | 21 | 
 
| 经验 | 39083 | 
 
| 最后登录 | 2025-8-7 | 
 
| 在线时间 | 950 小时 | 
 
 
 
 
 
Lv3.寻梦者 
	- 梦石
 - 0 
 
        - 星屑
 - 2116 
 
        - 在线时间
 - 950 小时
 
        - 注册时间
 - 2015-7-16
 
        - 帖子
 - 767
 
 
  
 
 | 
	
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员  
 
x
 
如題 
 
 
module TKTK_Bitmap   LARGE_BITMAP = true # 是否使用大型點陣圖的功能   DLL_NAME = 'tktk_bitmap'     ERROR_ALLOCATE_FAILED = -110002     @@png_save = Win32API.new(DLL_NAME, 'PngSaveA', 'p n i i', 'i')   @@blur = Win32API.new(DLL_NAME, 'Blur', 'n i', 'i')   @@change_tone = Win32API.new(DLL_NAME, 'ChangeTone', 'n i i i i', 'i')   @@clip_mask = Win32API.new(DLL_NAME, 'ClipMask', 'n n i i i', 'i')   @@invert = Win32API.new(DLL_NAME, 'InvertColor', 'n', 'i')   @@mosaic = Win32API.new(DLL_NAME, 'Mosaic', 'n i i i i i i', 'i')   @@address = Win32API.new(DLL_NAME, 'GetAddress', 'n', 'n')   @@get_pixel_data = Win32API.new(DLL_NAME, 'GetPixelData', 'n p i', 'i')   @@set_pixel_data = Win32API.new(DLL_NAME, 'SetPixelData', 'n p i', 'i')   @@blend_blt = Win32API.new(DLL_NAME, 'BlendBlt', 'n i i n i i i i i i', 'i')   #@@get_hwnd = Win32API.new(DLL_NAME, 'GetGameHWND', 'v', 'l')   @@change_size = Win32API.new(DLL_NAME, 'ChangeSize', 'n i i', 'i')   module_function     # PNG形式儲存   def png_save(bitmap,file_name,compression_level,filter)     return @@png_save.call(file_name, bitmap.object_id, compression_level, filter)   end     # 模糊效果   def blur(bitmap, r = 1)     return @@blur.call(bitmap.object_id, r)   end     # 更改顏色平衡?   def change_tone(bitmap, red = 0, green = 0, blue = 0, simplify = 1)     return @@change_tone.call(bitmap.object_id, red, green, blue, simplify)   end # 剪貼蒙版圖像(α乘法)   def clip_mask(g_bitmap, m_bitmap, x=0, y=0, outer=0)     return @@clip_mask.call(g_bitmap.object_id, m_bitmap.object_id, x, y, outer)   end     # 色的反轉   def invert(bitmap)     return @@invert.call(bitmap.object_id)   end     # 馬賽克效果   def mosaic(bitmap, msw=5, msh=5)     return self.mosaic_rect(bitmap, bitmap.rect, msw, msh)   end     # 馬賽克效果(範圍指定)   def mosaic_rect(bitmap, rect, msw=5, msh=5)     return @@mosaic.call(bitmap.object_id,     rect.x, rect.y, rect.width, rect.height, msw, msh)   end     # 獲取Bitmap資料位址   def address(bitmap)     return @@address.call(bitmap.object_id)   end     # 二進位資料獲取點Bitmap陣圖   def get_pixel_data(bitmap)     buffer = "bgra" * bitmap.width * bitmap.height     @@get_pixel_data.call(bitmap.object_id, buffer, buffer.size)     return buffer   end     #替換為Bitmap中的二進位資料   def set_pixel_data(bitmap, data)     return @@set_pixel_data.call(bitmap.object_id, data, data.size)   end     def blend_blt(dest_bmp, x, y, src_bmp, rect, blend_type=0, opacity=255)     @@blend_blt.call(dest_bmp.object_id, x, y, src_bmp.object_id,                 rect.x, rect.y, rect.width, rect.height,                 blend_type, opacity)   end     # 改變Bitmap的大小(風險)   def change_size(bitmap, new_width, new_height)     return -1 if (new_width <=0 or new_height <= 0)     result = @@change_size.call(bitmap.object_id, new_width, new_height)     if result == ERROR_ALLOCATE_FAILED       raise("tktk_bitmap:ERROR ALLOCATE FAILED")     end     return result   end   end   class Font   def marshal_dump;end   def marshal_load(obj);end end class Bitmap   # PNG 壓縮篩檢程式   PNG_NO_FILTERS   = 0x00   PNG_FILTER_NONE  = 0x08   PNG_FILTER_SUB   = 0x10   PNG_FILTER_UP    = 0x20   PNG_FILTER_AVG   = 0x40   PNG_FILTER_PAETH = 0x80   PNG_ALL_FILTERS  = (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP |                       PNG_FILTER_AVG | PNG_FILTER_PAETH)     # Marshal_dump   def _dump(limit)     return "" if self.disposed?     data = TKTK_Bitmap.get_pixel_data(self)     [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # ついでに圧縮   end     # Marshal_load   def self._load(str)     if str == ""       b = Bitmap.new(1,1)       b.dispose       return b     end     w, h, zdata = str.unpack("LLa*"); b = new(w, h)     TKTK_Bitmap.set_pixel_data(b, Zlib::Inflate.inflate(zdata))     return b   end       def address     TKTK_Bitmap.address(self)   end     #         模糊效果   def blur2(r=1)     TKTK_Bitmap.blur(self, r)   end     # 色調變化   def change_tone(red, green, blue, simplify = 1)     TKTK_Bitmap.change_tone(self, red, green, blue, simplify)   end     # 剪切   def clip_mask(bitmap, x=0, y=0, outer=0)     TKTK_Bitmap.clip_mask(self, bitmap, x, y, outer)   end     # 反相顏色   def invert     TKTK_Bitmap.invert(self)   end     # 馬賽克效果   def mosaic(msw=5, msh=5)     TKTK_Bitmap.mosaic(self, msw, msh)   end     # 馬賽克效果 (指定區域)   def mosaic_rect(rect=self.rect, msw=5, msh=5)     TKTK_Bitmap.mosaic_rect(self, rect, msw, msh)   end     # 混合   def blend_blt(x, y, src_bmp, rect, blend_type=0, opacity=255)     return if opacity <= 0     TKTK_Bitmap.blend_blt(self, x, y, src_bmp, rect, blend_type, opacity)   end     #Png 格式保存   def png_save(outp, level = 9, filter = PNG_NO_FILTERS)     if (TKTK_Bitmap.png_save(self, outp, level, filter) != 0)       raise("Bitmap\#png_save failed")     end   end     # 允許更大的 bitmap.new (危険)   # 寬度 * 高度大約是1073741823   if TKTK_Bitmap::LARGE_BITMAP     class << self       unless method_defined?(:_hn_large_bm__new)         alias :_hn_large_bm__new :new       end       def new(*args)         if args.size == 2 && args[0] * args[1] >= 4194304           new_width = args[0]           new_height = args[1]           # 暫時以小尺寸作成           bitmap = _hn_large_bm__new(16, 16)           TKTK_Bitmap.change_size(bitmap, new_width, new_height)           return bitmap         else           _hn_large_bm__new(*args)         end       end     end # Bitmap.new   end end # CLASS Bitmap 
 
 module TKTK_Bitmap  
  LARGE_BITMAP = true # 是否使用大型點陣圖的功能  
  DLL_NAME = 'tktk_bitmap'  
   
  ERROR_ALLOCATE_FAILED = -110002  
   
  @@png_save = Win32API.new(DLL_NAME, 'PngSaveA', 'p n i i', 'i')  
  @@blur = Win32API.new(DLL_NAME, 'Blur', 'n i', 'i')  
  @@change_tone = Win32API.new(DLL_NAME, 'ChangeTone', 'n i i i i', 'i')  
  @@clip_mask = Win32API.new(DLL_NAME, 'ClipMask', 'n n i i i', 'i')  
  @@invert = Win32API.new(DLL_NAME, 'InvertColor', 'n', 'i')  
  @@mosaic = Win32API.new(DLL_NAME, 'Mosaic', 'n i i i i i i', 'i')  
  @@address = Win32API.new(DLL_NAME, 'GetAddress', 'n', 'n')  
  @@get_pixel_data = Win32API.new(DLL_NAME, 'GetPixelData', 'n p i', 'i')  
  @@set_pixel_data = Win32API.new(DLL_NAME, 'SetPixelData', 'n p i', 'i')  
  @@blend_blt = Win32API.new(DLL_NAME, 'BlendBlt', 'n i i n i i i i i i', 'i')  
  #@@get_hwnd = Win32API.new(DLL_NAME, 'GetGameHWND', 'v', 'l')  
  @@change_size = Win32API.new(DLL_NAME, 'ChangeSize', 'n i i', 'i')  
  module_function  
   
  # PNG形式儲存  
  def png_save(bitmap,file_name,compression_level,filter)  
    return @@png_save.call(file_name, bitmap.object_id, compression_level, filter)  
  end  
   
  # 模糊效果  
  def blur(bitmap, r = 1)  
    return @@blur.call(bitmap.object_id, r)  
  end  
   
  # 更改顏色平衡?  
  def change_tone(bitmap, red = 0, green = 0, blue = 0, simplify = 1)  
    return @@change_tone.call(bitmap.object_id, red, green, blue, simplify)  
  end  
# 剪貼蒙版圖像(α乘法)  
  def clip_mask(g_bitmap, m_bitmap, x=0, y=0, outer=0)  
    return @@clip_mask.call(g_bitmap.object_id, m_bitmap.object_id, x, y, outer)  
  end  
   
  # 色的反轉  
  def invert(bitmap)  
    return @@invert.call(bitmap.object_id)  
  end  
   
  # 馬賽克效果  
  def mosaic(bitmap, msw=5, msh=5)  
    return self.mosaic_rect(bitmap, bitmap.rect, msw, msh)  
  end  
   
  # 馬賽克效果(範圍指定)  
  def mosaic_rect(bitmap, rect, msw=5, msh=5)  
    return @@mosaic.call(bitmap.object_id,  
    rect.x, rect.y, rect.width, rect.height, msw, msh)  
  end  
   
  # 獲取Bitmap資料位址  
  def address(bitmap)  
    return @@address.call(bitmap.object_id)  
  end  
   
  # 二進位資料獲取點Bitmap陣圖  
  def get_pixel_data(bitmap)  
    buffer = "bgra" * bitmap.width * bitmap.height  
    @@get_pixel_data.call(bitmap.object_id, buffer, buffer.size)  
    return buffer  
  end  
   
  #替換為Bitmap中的二進位資料  
  def set_pixel_data(bitmap, data)  
    return @@set_pixel_data.call(bitmap.object_id, data, data.size)  
  end  
   
  def blend_blt(dest_bmp, x, y, src_bmp, rect, blend_type=0, opacity=255)  
    @@blend_blt.call(dest_bmp.object_id, x, y, src_bmp.object_id,  
                rect.x, rect.y, rect.width, rect.height,  
                blend_type, opacity)  
  end  
   
  # 改變Bitmap的大小(風險)  
  def change_size(bitmap, new_width, new_height)  
    return -1 if (new_width <=0 or new_height <= 0)  
    result = @@change_size.call(bitmap.object_id, new_width, new_height)  
    if result == ERROR_ALLOCATE_FAILED  
      raise("tktk_bitmap:ERROR ALLOCATE FAILED")  
    end  
    return result  
  end  
   
end  
   
class Font  
  def marshal_dump;end  
  def marshal_load(obj);end  
end  
class Bitmap  
  # PNG 壓縮篩檢程式  
  PNG_NO_FILTERS   = 0x00  
  PNG_FILTER_NONE  = 0x08  
  PNG_FILTER_SUB   = 0x10  
  PNG_FILTER_UP    = 0x20  
  PNG_FILTER_AVG   = 0x40  
  PNG_FILTER_PAETH = 0x80  
  PNG_ALL_FILTERS  = (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP |  
                      PNG_FILTER_AVG | PNG_FILTER_PAETH)  
   
  # Marshal_dump  
  def _dump(limit)  
    return "" if self.disposed?  
    data = TKTK_Bitmap.get_pixel_data(self)  
    [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # ついでに圧縮  
  end  
   
  # Marshal_load  
  def self._load(str)  
    if str == ""  
      b = Bitmap.new(1,1)  
      b.dispose  
      return b  
    end  
    w, h, zdata = str.unpack("LLa*"); b = new(w, h)  
    TKTK_Bitmap.set_pixel_data(b, Zlib::Inflate.inflate(zdata))  
    return b  
  end    
   
  def address  
    TKTK_Bitmap.address(self)  
  end  
   
  #         模糊效果  
  def blur2(r=1)  
    TKTK_Bitmap.blur(self, r)  
  end  
   
  # 色調變化  
  def change_tone(red, green, blue, simplify = 1)  
    TKTK_Bitmap.change_tone(self, red, green, blue, simplify)  
  end  
   
  # 剪切  
  def clip_mask(bitmap, x=0, y=0, outer=0)  
    TKTK_Bitmap.clip_mask(self, bitmap, x, y, outer)  
  end  
   
  # 反相顏色  
  def invert  
    TKTK_Bitmap.invert(self)  
  end  
   
  # 馬賽克效果  
  def mosaic(msw=5, msh=5)  
    TKTK_Bitmap.mosaic(self, msw, msh)  
  end  
   
  # 馬賽克效果 (指定區域)  
  def mosaic_rect(rect=self.rect, msw=5, msh=5)  
    TKTK_Bitmap.mosaic_rect(self, rect, msw, msh)  
  end  
   
  # 混合  
  def blend_blt(x, y, src_bmp, rect, blend_type=0, opacity=255)  
    return if opacity <= 0  
    TKTK_Bitmap.blend_blt(self, x, y, src_bmp, rect, blend_type, opacity)  
  end  
   
  #Png 格式保存  
  def png_save(outp, level = 9, filter = PNG_NO_FILTERS)  
    if (TKTK_Bitmap.png_save(self, outp, level, filter) != 0)  
      raise("Bitmap\#png_save failed")  
    end  
  end  
   
  # 允許更大的 bitmap.new (危険)  
  # 寬度 * 高度大約是1073741823  
  if TKTK_Bitmap::LARGE_BITMAP  
    class << self  
      unless method_defined?(:_hn_large_bm__new)  
        alias :_hn_large_bm__new :new  
      end  
      def new(*args)  
        if args.size == 2 && args[0] * args[1] >= 4194304  
          new_width = args[0]  
          new_height = args[1]  
          # 暫時以小尺寸作成  
          bitmap = _hn_large_bm__new(16, 16)  
          TKTK_Bitmap.change_size(bitmap, new_width, new_height)  
          return bitmap  
        else  
          _hn_large_bm__new(*args)  
        end  
      end  
    end # Bitmap.new  
  end  
end # CLASS Bitmap  
 
  
 
Scripts.rar
(150.76 KB, 下载次数: 41)
 |   
 
 
 
 |