所以让我先说明我是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
答案 0 :(得分:0)
只做一个:
require 'open-url'
然后
@pic = open("http://website.com/imgs/image.png")
然后像对待任何其他File
答案 1 :(得分:0)
那应该是
require 'open-uri'
而不是
require 'open-url'