0

因此,让我以我是 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
4

2 回答 2

0

那应该是

require 'open-uri'

并不是

require 'open-url'
于 2010-11-02T16:37:33.363 回答
0

只需做一个:

require 'open-url'

然后

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

然后像对待任何其他人一样对待它File

于 2010-11-01T19:45:01.320 回答