Project1

标题: 关于字体的描边 [打印本页]

作者: 喵呜喵5    时间: 2014-5-1 14:01
标题: 关于字体的描边
Font类自己的outline属性允许给字体增加描边,但是描边的厚度只有1个像素,请问如何实现2个像素乃至任意像素的字体描边?
作者: Sion    时间: 2014-5-1 14:11
photoshop
作者: taroxd    时间: 2014-5-1 14:56
试着只用脚本编辑器写了一下,结果就是个杯具
所以说这种东西应该不太能只用RGSS3来实现吧……

然后送一段杯具的代码=。=

RUBY 代码复制
  1. class Font
  2.  
  3.   attr_accessor :outline_size
  4.  
  5.   singleton_class.send :attr_accessor, :default_outline_size
  6.  
  7.   self.default_outline_size = 1
  8.  
  9.   alias initialize_without_outline initialize
  10.  
  11.   def initialize(*args)
  12.     initialize_without_outline(*args)
  13.     @outline_size = Font.default_outline_size
  14.   end
  15.  
  16. end
  17.  
  18. class Bitmap
  19.  
  20.   alias draw_text_without_outline draw_text
  21.  
  22.   def draw_text(*args)
  23.  
  24.     draw_text_without_outline(*args)
  25.     return unless font.outline_size
  26.  
  27.     white = Color.new(255,255,255)
  28.  
  29.     temp = Bitmap.new(width, height)
  30.     temp.fill_rect(0, 0, width, height, white)
  31.     temp.draw_text_without_outline(*args)
  32.  
  33.     width.times do |x|
  34.       height.times do |y|
  35.         unless temp.get_pixel(x, y) == white
  36.           (x - font.outline_size + 1).upto(x + font.outline_size - 1) do |i|
  37.             (y - font.outline_size + 1).upto(y + font.outline_size - 1) do |j|
  38.               set_pixel(i, j, font.out_color)
  39.             end
  40.           end
  41.         end
  42.       end
  43.     end
  44.  
  45.     temp.dispose
  46.  
  47.   end
  48.  
  49. end

作者: 无脑之人    时间: 2014-5-2 15:30
偏移几像素多画几遍呗233,虽然这样很没效率




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1