2012-05-31 54 views
1

我正在製作一個簡單的圖像程序。我安裝了chunky_png寶石來處理PNG圖像,但我不知道如何在窗口中繪製:如何使用Ruby來顯示圖像?

require 'chunky_png' 
require 'tk' 
town = ChunkyPNG::Image.from_file("town.png") 
root = TkRoot.new 
Tk.mainloop 

什麼我需要做的,畫在根窗口中的圖像?

回答

0

看一看在tk文件http://www.tutorialspoint.com/ruby/ruby_tk_fonts_colors_images.htm

這裏是如何顯示圖像的例子:

require 'tk' 

$resultsVar = TkVariable.new 
root = TkRoot.new 
root.title = "Window" 

image = TkPhotoImage.new 
image.file = "zara.gif" 

label = TkLabel.new(root) 
label.image = image 
label.place('height' => image.height, 
      'width' => image.width, 
      'x' => 10, 'y' => 10) 
Tk.mainloop