| 
				
				
累计送礼:0 个
 累计收礼:0 个
 TA的每日心情|  | 开心 2025-10-18 22:41
 | 
|---|
 签到天数: 165 天 连续签到: 1 天 [LV.7]常住居民III 
 管理员   
 
    
        VIP6  
        卡币14603  
        OK点16  
    推广点0  
    同能卷0  
	积分17724 
 
  | 
 
| 练习结构体与intrinsics 
使用GDI进行描绘文本,修复alpha通道,模拟Bitmap#blt进行颜色混合,HSL颜色渐变。 
多个字符情况下,虽然比Bitmap#draw_text快不少,但不考虑颜色混合效果的话,gdiplus都可以跑到3000+次/秒
 
bug:写着玩,只处理了 4 * n 部分宽度的像素,尽量文本尾部远离 位图右边界。 
RUBY 代码 复制代码module TextBoard  @@pBoard = 0  dll = "TextBoard.dll"  TB_open = Win32API.new(dll, 'TB_open', 'V', 'L')  TB_close = Win32API.new(dll, 'TB_close', 'L', 'L')  TB_select_bitmap = Win32API.new(dll, 'TB_select_bitmap', 'LL', 'L')  TB_set_font = Win32API.new(dll, 'TB_set_font', 'LLPLLLL', 'L')  TB_draw = Win32API.new(dll, 'TB_draw', 'LPLLLLL', 'L')  module_function  defopen    @@pBoard = TB_open.call()if @@pBoard == 0  end  def close    if @@pBoard != 0      TB_close.call(@@pBoard)      @@pBoard = 0    end  end  def select_bitmap(bitmap)    TB_select_bitmap.call(@@pBoard, bitmap)if @@pBoard != 0  end  # TB_open时字体默认设置下面的默认值,不改变字体参数的话可以不用调用此方法  # nWeight: 0..1000的整百数;700为粗体  def set_font(font_size = 22, font_name = "黑体", nWeight = 0,    bItalic = 0, bUnderline = 0, bStrikeOut = 0)    TB_set_font.call(@@pBoard, font_size, font_name, nWeight, bItalic,\      bUnderline, bStrikeOut)if @@pBoard != 0  end  # mode: 0 => 水平渐变;非0 => 垂直渐变  def draw(text, dx, dy, colorA, colorB = nil, mode = 0)    if @@pBoard != 0      TB_draw.call(@@pBoard, text, dx, dy, mode, colorA, colorB || colorA)    end  endend
RUBY 代码 复制代码# 简单的使用示例bitmap = Bitmap.new(640, 480)text = "文字描绘测试123-ABCD"font_size = 22font_name = "黑体"TextBoard.openTextBoard.select_bitmap(bitmap)TextBoard.set_font(font_size, font_name, 0)cA, cB = Color.new(255, 0, 0), Color.new(0, 255, 0)TextBoard.draw(text, 0, 100, cA, cB, 0)TextBoard.draw(text, 0, 200, cA, cB, 1)TextBoard.close
             本帖来自P1论坛作者RPGzh500223,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=489677   若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。 | 
 
x本帖子中包含更多资源您需要 登录 才可以下载或查看,没有账号?立即注册  |