如何使用 Ruby 显示图像



我正在制作一个简单的图像程序。我安装了chunky_png gem来处理png图像,但我不知道如何在窗口中绘制:

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

根窗口中绘制图像需要做什么?

查看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

最新更新