File: inline.rb

package info (click to toggle)
ruby-gnome2 0.12.0-2sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,820 kB
  • ctags: 7,421
  • sloc: ansic: 61,387; ruby: 17,307; makefile: 85; xml: 35; sql: 13
file content (38 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
=begin
  inline.rb - Ruby/GdkPixbuf sample script.

  Copyright (c) 2004 Ruby-GNOME2 Project Team
  This program is licenced under the same licence as Ruby-GNOME2.

  $Id: inline.rb,v 1.1 2004/08/14 07:00:50 mutoh Exp $
=end

require 'gtk2'

pixbuf = Gdk::Pixbuf.new("gnome-foot.png")

#pixbuf = Gdk::Pixbuf.new(ARGV[0])

# Create Gdk::Pixbuf from pixels(String).
pixbuf2 = Gdk::Pixbuf.new(pixbuf.pixels, Gdk::Pixbuf::COLORSPACE_RGB, 
                          true, pixbuf.bits_per_sample, 
                          pixbuf.width, pixbuf.height, 
                          pixbuf.rowstride)

# Create Gdk::Pixbuf from an array of numbers 
# which created by Gdk::Pixdata#serialize.
pixdata = Gdk::Pixdata.from_pixbuf(pixbuf, false)
data = pixdata.serialize
pixbuf3 = Gdk::Pixbuf.new(data, false)

# Create Gdk::Pixbuf from Gdk::Pixbuf.
pixbuf4 = Gdk::Pixbuf.new(pixbuf, 10, 10, 20, 20)

Gtk.init
vbox = Gtk::VBox.new
vbox.add(Gtk::Image.new(pixbuf))
vbox.add(Gtk::Image.new(pixbuf2))
vbox.add(Gtk::Image.new(pixbuf3))
vbox.add(Gtk::Image.new(pixbuf4))
Gtk::Window.new.add(vbox).show_all
Gtk.main