因此,让我以我是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
发布于 2010-11-03 00:37:33
那应该是
require 'open-uri'
而不是
require 'open-url'
发布于 2010-11-02 03:45:01
只需执行以下操作:
require 'open-url'
然后
@pic = open("http://website.com/imgs/image.png")
然后像对待任何其他File
一样对待它
https://stackoverflow.com/questions/4072474
复制相似问题