別のやりかたで縁取り

なにをそんなにこだわっているのか。

いままではフォントの端1ピクセルを黒くしようとしていたが、今回はフォントの外側の透明部分1ピクセルを黒くしてみた。
これなら小さくても綺麗に見える。

アルゴリズムは試行錯誤で悲惨なものになってしまっているが。

# DXRuby1.0.6サンプル
require 'dxruby'

font = Font.new(32)
image = Image.new(200,200).drawFont(0,0,"",font)
Window.bgcolor = [255,255,255]
Window.width = 200
Window.height = 200

# 半透明の部分を黒にする
for y in 0..199
  for x in 0..199
    temp = image[x, y][0]
    image[x, y] = [255-temp, 0, 0, 0] if temp != 255 and temp != 0
  end
end
image2 = image.dup # dupできるよーになったよ!

# 透明の部分に対して、横の影響を与える
for y in 1..198
  for x in 1..198
    if image.compare(x, y, [0,0,0,0])
      temp_color = 0
      count = 0
      if image[x-1, y][0] != 0
        if image.compare(x-1, y, [255,255,255])
          temp_color += image[x-1, y][0]
        else
          temp_color += 255-image[x-1, y][0]
        end
        count+=1
      end
      if image[x+1, y][0] != 0
        if image.compare(x+1, y, [255,255,255])
          temp_color += image[x+1, y][0]
        else
          temp_color += 255-image2[x+1, y][0]
        end
        count+=1
      end
      if image[x, y-1][0] != 0
        if image.compare(x, y-1, [255,255,255])
          temp_color += image[x, y-1][0]
        else
          temp_color += 255-image2[x, y-1][0]
        end
        count+=1
      end
      if image[x, y+1][0] != 0
        if image.compare(x, y+1, [255,255,255])
          temp_color += image[x, y+1][0]
        else
          temp_color += 255-image2[x-1, y+1][0]
        end
        count+=1
      end
      temp_color /= count if count > 0
      image2[x,y] = [temp_color,0,0,0] if count > 0
    end
  end
end

Window.loop do
  Window.draw(0,0,image2)
end

と思ったが背景を赤にしてみたらおかしく。
α値の計算が間違っているのだろう。

画像処理の経験・知識が無いとなかなかうまいこといかない。