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

发布于 2024-09-30 08:16:32 字数 592 浏览 0 评论 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

so let me preface this with the fact that I am a beginner at ruby and FXruby. I would like to know how I can fetch images by using a URL. This is the code I used when getting them off my desktop:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌酱 2024-10-07 08:16:32

那应该是

require 'open-uri'

而不是

require 'open-url'

That should be

require 'open-uri'

and not

require 'open-url'
月下客 2024-10-07 08:16:32

只需执行:

require 'open-url'

然后

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

然后像对待任何其他文件一样对待它

Just do a:

require 'open-url'

then

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

Then treat it as you would treat any other File

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文