man Gtk2::Gdk::Pixbuf () - Gtk2::Gdk::Pixbuf

NAME

Gtk2::Gdk::Pixbuf

HIERARCHY

  Glib::Object
  +----Gtk2::Gdk::Pixbuf

METHODS

Creates a new Gtk2::Gdk::Pixbuf out of in-memory image data. Currently only RGB images with 8 bits per sample are supported. In C this function allows you to wrap a GdkPixbuf structure around existing pixel data. In Perl, we have to use CWpack to generate a scalar containing the pixel data, and pass that scalar to CWnew_from_data, which copies the scalar to keep it around. It also manages the memory automagically, so there's no need for a destruction notifier function. This all means that if you change your copy of the data scalar later, the pixbuf will not reflect that, but because of the way perl manages string data and scalars, it would be pretty fragile to do that in the first place. If you need to modify a pixbuf's data after it has been created, you can create new pixbufs for the changed regions and use CW$pixbuf->composite, or try a different approach (possibly use a server-side pixmap and gdk drawing primitives, or something like libart).

pixbuf = Gtk2::Gdk::Pixbuf->new_from_file ($filename)

May croak with a Glib::Error in $@ on failure. May croak with a Glib::Error in $@ on failure. May croak with a Glib::Error in $@ on failure. Gtk+ ships with a tool called CWgdk-pixbuf-csource, which turns any image understood by gdk-pixbuf into the C syntax of the declaration of a static data structure containing that image data, to be #included directly into your source code. CWgdk_pixbuf_new_from_inline creates a new GdkPixbuf from that data structure. Currently, this is not very easy to do from Perl. The output of CWgdk-pixbuf-csource must be mangled rather ruthlessly to create valid Perl code using pack and translation from C string escapes to valid Perl string escapes (for encoding and interpretation isses). Because Perl scalars are garbage collected, it's rather rare to have the ability to use static data, so $copy_pixels defaults to true; if you can guarantee the image data will outlive the pixbuf you can pass false here and save some memory. For more information, see the description of CWgdk_pixbuf_new_from_inline in the C API reference at http://gtk.org/api/ . May croak with a Glib::Error in $@ on failure.

pixbuf = Gtk2::Gdk::Pixbuf->new_from_xpm_data (...)

* ... (list) xpm data as a list of strings (see discussion)
X Pixel Map (XPM) files are designed to be easy to edit and easy to include directly into C programs. The file format is the C syntax of the declaration and initialization of a variable containing an array of strings. CWnew_from_xpm_data allows you to create an image from such data included directly in your program source. Since XPM files are C syntax, you must mangle that source a bit to work in a Perl program. For example, this is a valid xpm, but it is not valid Perl code:
 /* XPM */
 static char * test_xpm[] = {
 "4 4 3 1",
 "      c None",
 ".     c red",
 "+     c blue",
 ".. +",
 ". ++",
 " ++.",
 "++.."};
You'll need to change the array declaration format, and change the double-quoted strings to single-quoted to avoid Perl interpreting any chars in the strings as special.
 my @test_xpm = (
 '4 4 3 1',
 '      c None',
 '.     c red',
 '+     c blue',
 '.. +',
 '. ++',
 ' ++.',
 '++..');
 $pixbuf = Gtk2::Gdk::Pixbuf->new_from_xpm_data (@test_xpm);
[It's only two or three regexes... Perhaps we should distribute a script to convert XPM files to the proper format?]

list = Gtk2::Gdk::Pixbuf->get_file_info ($filename)

$pixbuf->fill ($pixel)

Clear $pixbuf to contain only the value given in $pixel.

list = Gtk2::Gdk::Pixbuf->get_formats

Returns a list of hashes with information about the formats supported by Gtk2::Gdk::Pixbuf. Fetch pixels from a Gtk2::Gdk::Drawable as a Gtk2::Gdk::Pixbuf. Returns a new Gtk2::Gdk::Pixbuf if you use the class form, or $pixbuf if you call it on an existing pixbuf. Fetch pixels from a Gtk2::Gdk::Image as a Gtk2::Gdk::Pixbuf. Returns a new Gtk2::Gdk::Pixbuf if you use the class form, or $pixbuf if you call it on an existing pixbuf.

* ... (list) list of key-value save options
Save $pixbuf to a file named $filename, in the format $type, which is currently jpeg or png. The function will croak if there is an error, which may arise from file- or image format-related issues. Any values in ... should be key/value string pairs that modify the saving parameters. For example:
 $pixbuf->save ($filename, 'jpeg', quality => '100');
Currently only a few parameters exist. JPEG images can be saved with a quality parameter; its value should be in the range [0,100]. Text chunks can be attached to PNG images by specifying parameters of the form tEXt::key, where key is an ASCII string of length 1-79. The values are UTF-8 encoded strings. (This is a quote from the C API reference; note that the C API reference is the canonical source for this information.) May croak with a Glib::Error in $@ on failure.

PROPERTIES

'bits-per-sample' (integer : readable / writable / construct-only / private)
The number of bits per sample
'colorspace' (Gtk2::Gdk::Colorspace : readable / writable / construct-only / private)
The colorspace in which the samples are interpreted
'has-alpha' (boolean : readable / writable / construct-only / private)
Whether the pixbuf has an alpha channel
'height' (integer : readable / writable / construct-only / private)
The number of rows of the pixbuf
'n-channels' (integer : readable / writable / construct-only / private)
The number of samples per pixel
'pixels' (gpointer : readable / writable / construct-only / private)
A pointer to the pixel data of the pixbuf
'rowstride' (integer : readable / writable / construct-only / private)
The number of bytes between the start of a row and the start of the next row
'width' (integer : readable / writable / construct-only / private)
The number of columns of the pixbuf

ENUMS AND FLAGS

enum Gtk2::Gdk::Colorspace

* 'rgb' / 'GDK_COLORSPACE_RGB'

enum Gtk2::Gdk::InterpType

* 'nearest' / 'GDK_INTERP_NEAREST'
* 'tiles' / 'GDK_INTERP_TILES'
* 'bilinear' / 'GDK_INTERP_BILINEAR'
* 'hyper' / 'GDK_INTERP_HYPER'

enum Gtk2::Gdk::PixbufAlphaMode

* 'bilevel' / 'GDK_PIXBUF_ALPHA_BILEVEL'
* 'full' / 'GDK_PIXBUF_ALPHA_FULL'

enum Gtk2::Gdk::PixbufError

* 'corrupt-image' / 'GDK_PIXBUF_ERROR_CORRUPT_IMAGE'
* 'insufficient-memory' / 'GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY'
* 'bad-option' / 'GDK_PIXBUF_ERROR_BAD_OPTION'
* 'unknown-type' / 'GDK_PIXBUF_ERROR_UNKNOWN_TYPE'
* 'unsupported-operation' / 'GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION'
* 'failed' / 'GDK_PIXBUF_ERROR_FAILED'

enum Gtk2::Gdk::PixbufRotation

* 'none' / 'GDK_PIXBUF_ROTATE_NONE'
* 'counterclockwise' / 'GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE'
* 'upsidedown' / 'GDK_PIXBUF_ROTATE_UPSIDEDOWN'
* 'clockwise' / 'GDK_PIXBUF_ROTATE_CLOCKWISE'

enum Gtk2::Gdk::RgbDither

* 'none' / 'GDK_RGB_DITHER_NONE'
* 'normal' / 'GDK_RGB_DITHER_NORMAL'
* 'max' / 'GDK_RGB_DITHER_MAX'

SEE ALSO

Gtk2, Glib::Object

COPYRIGHT

Copyright (C) 2003-2005 by the gtk2-perl team.

This software is licensed under the LGPL. See Gtk2 for a full notice.