wxRubyでFileDialogを使った選択した画像をそのまま表示するサンプル。
Wx::Frame.refresh
Wx::Frame.update
の両方を呼ばないとダメらしい。
open_image.rb
require 'wx'
class MyApp < Wx::App
def on_init
MyFrame.new.show
end
end
class MyFrame < Wx::Frame
def initialize
super(nil, -1, "Image Test")
menu_bar = Wx::MenuBar.new
file_menu = Wx::Menu.new
file_menu.append(Wx::ID_OPEN, '&Open', 'Open Image')
menu_bar.append(file_menu, '&File')
set_menu_bar(menu_bar)
evt_menu(Wx::ID_OPEN) {|event| menu_open(event)}
end
def menu_open(event)
dlg = Wx::FileDialog.new(self, "Choose a file", Dir.getwd(), "")
if dlg.show_modal() == Wx::ID_OK
file = dlg.get_paths[0]
img = Wx::Image.new(file)
@bitmap.destroy unless @bitmap.nil?
@bitmap = Wx::StaticBitmap.new( self, -1, img.convert_to_bitmap, [0,0], [img.width, img.height ] )
self.refresh
self.update
end
end
end
MyApp.new.main_loop
※再描写がおかしい?