[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Gdk::Pixbuf from an URL

Michael Gebhart

2/11/2005 3:05:00 PM

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
2 Answers

Masao Mutoh

2/11/2005 5:50:00 PM

0

Hi,

On Sat, 12 Feb 2005 00:10:01 +0900
Michael Gebhart <mail@miketech.net> wrote:

> 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...) { |f|
loader.last_write(f.read)
}
pixbuf = loader.pixbuf

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

#This example for Ruby-1.8.x or later.

--
:% Masao Mutoh<mutoh@highway.ne.jp>


Michael Gebhart

2/11/2005 6:10:00 PM

0

Great.. really great!

Thanks a lot

Michael