Gdk::Pixbuf from an URL

M

Michael Gebhart

Hi,

I wanna display a image from the internet in a Gdk::pixbuf. Pixbuf.new
only accepts files on the harddisc. So my idea was to use
Pixbuf#from_image. But therefore I have to load the image in a Gdk::Image.
I've found out, that I can download an image with net/http. I can read the
file, but how can I put it in a Gdk::Image? Any ideas?

Greetings

Michael
 
M

Masao Mutoh

Hi,

Hi,

I wanna display a image from the internet in a Gdk::pixbuf. Pixbuf.new
only accepts files on the harddisc. So my idea was to use
Pixbuf#from_image. But therefore I have to load the image in a Gdk::Image.
I've found out, that I can download an image with net/http. I can read the
file, but how can I put it in a Gdk::Image? Any ideas?

Interesting Quiz ;).

My answer is:

-------------------
require 'open-uri'
require 'gtk2'

Gtk.init
loader = Gdk::pixbufLoader.new
open("http://www.ruby-lang.org/image/title.gif") { |f|
loader.last_write(f.read)
}
pixbuf = loader.pixbuf

Gtk::Window.new.add(Gtk::Image.new(pixbuf)).show_all
Gtk.main
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,192
Latest member
KalaReid2

Latest Threads

Top