如何在FXRuby中获取互联网图像?

时间:2010-11-01 19:40:38

标签: ruby fxruby

所以让我先说明我是ruby和FXruby的初学者。我想知道如何使用URL获取图像。这是我从桌面上取下代码时使用的代码:

require 'rubygems'

require 'fox16'

include Fox


class Image_Viewer <FXMainWindow
  def initialize(app)
    super(app, "Image Viewer", :opts => DECOR_ALL, :width => 500, :height => 450) 
    @pic = File.open("/Users/AdamAshwal/Desktop/image.jpg", "rb")
    @pic2 = FXJPGImage.new(app, @pic.read)
    FXImageFrame.new(self, @pic2)

end 
  def create
    super
    self.show(PLACEMENT_SCREEN)
end

end


app = FXApp.new
mainwin = Image_Viewer.new(app)

app.create
app.run

2 个答案:

答案 0 :(得分:0)

只做一个:

require 'open-url'

然后

@pic = open("http://website.com/imgs/image.png")    

然后像对待任何其他File

一样对待它

答案 1 :(得分:0)

那应该是

require 'open-uri'

而不是

require 'open-url'