#!ruby -Ku # -*- mode: ruby; encoding: utf-8 -*- # Last updated: <2014/06/03 07:36:32 +0900> # # cairo のテスト。 # StringIO で DXRuby の Image にデータを渡してみる版 require 'cairo' require 'dxruby' require 'stringio' w, h = 640 - 32, 480 - 32 surface = Cairo::ImageSurface.new(w, h) context = Cairo::Context.new(surface) # 円を書く context.set_line_width(12) context.set_source_color(Cairo::Color::GREEN) r = h / 3 x, y, rw, rh = 100, 30, 50, 50 context.arc(w/2, h/2, r, 0, 2 * Math::PI) context.fill_preserve context.set_source_color(Cairo::Color::RED) context.stroke # StringIOを使って png出力、かつ、Image生成 temp = StringIO.new("", 'w+') surface.write_to_png(temp) temp.rewind img = Image.loadFromFileInMemory(temp.read) # DXRubyで表示 Window.bgcolor = [64, 64, 64] Window.loop do break if Input.keyPush?(K_ESCAPE) Window.draw(16, 16, img) end