Next:
Gtk2::Gdk::PixbufAnimation
Previous:
Gtk2::Gdk::PangoRenderer
 [Gtk2-Perl - Table of Contents][Gtk2-Perl - Index]

Gtk2::Gdk::Pixbuf



NAME

Gtk2::Gdk::Pixbuf

HIERARCHY

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

METHODS

pixbuf = Gtk2::Gdk::Pixbuf->new ($colorspace, $has_alpha, $bits_per_sample, $width, $height)

pixbuf = Gtk2::Gdk::Pixbuf->new_from_data ($data, $colorspace, $has_alpha, $bits_per_sample, $width, $height, $rowstride)

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 pack to generate a scalar containing the pixel data, and pass that scalar to new_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 $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.

pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale ($filename, $width, $height, $preserve_aspect_ratio)

May croak with a Glib::Error in $@ on failure.

Since: gtk+ 2.6

pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_size ($filename, $width, $height)

May croak with a Glib::Error in $@ on failure.

Since: gtk+ 2.4

pixbuf = Gtk2::Gdk::Pixbuf->new_from_inline ($data, $copy_pixels=TRUE)

Gtk+ ships with a tool called gdk-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. gdk_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 gdk-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 gdk_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 (...)

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. new_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?]

pixbuf = $src_pixbuf->new_subpixbuf ($src_x, $src_y, $width, $height)

pixbuf = $pixbuf->add_alpha ($substitute_color, $r, $g, $b)

pixbuf = $src->apply_embedded_orientation

Since: gtk+ 2.11

integer = $pixbuf->get_bits_per_sample

colorspace = $pixbuf->get_colorspace

$src->composite ($dest, $dest_x, $dest_y, $dest_width, $dest_height, $offset_x, $offset_y, $scale_x, $scale_y, $interp_type, $overall_alpha)

$src->composite_color ($dest, $dest_x, $dest_y, $dest_width, $dest_height, $offset_x, $offset_y, $scale_x, $scale_y, $interp_type, $overall_alpha, $check_x, $check_y, $check_size, $color1, $color2)

pixbuf or undef = $src->composite_color_simple ($dest_width, $dest_height, $interp_type, $overall_alpha, $check_size, $color1, $color2)

pixbuf = $pixbuf->copy

$src_pixbuf->copy_area ($src_x, $src_y, $width, $height, $dest_pixbuf, $dest_x, $dest_y)

(format, width, height) = $pixbuf->get_file_info ($filename)

Parses enough of $filename to determine and return the format and size. If the format is unknown or the file can't be opened, returns an empty list.

Since: gtk+ 2.4

$pixbuf->fill ($pixel)

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

pixbuf = $src->flip ($horizontal)

Since: gtk+ 2.6

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

Returns a list of hashes with information about the formats supported by Gtk2::Gdk::Pixbuf.

Since: gtk+ 2.2

pixbuf = Gtk2::Gdk::Pixbuf->get_from_drawable ($src, $cmap, $src_x, $src_y, $dest_x, $dest_y, $width, $height)

pixbuf = $pixbuf->get_from_drawable ($src, $cmap, $src_x, $src_y, $dest_x, $dest_y, $width, $height)

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.

pixbuf = Gtk2::Gdk::Pixbuf->get_from_image ($src, $cmap, $src_x, $src_y, $dest_x, $dest_y, $width, $height)

pixbuf = $pixbuf->get_from_image ($src, $cmap, $src_x, $src_y, $dest_x, $dest_y, $width, $height)

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.

boolean = $pixbuf->get_has_alpha

integer = $pixbuf->get_height

integer = $pixbuf->get_n_channels

string or undef = $pixbuf->get_option ($key)

scalar = $pixbuf->get_pixels

pixmap = $pixbuf->render_pixmap_and_mask ($alpha_threshold)

(pixmap, mask) = $pixbuf->render_pixmap_and_mask ($alpha_threshold)

pixmap = $pixbuf->render_pixmap_and_mask_for_colormap ($colormap, $alpha_threshold)

(pixmap, mask) = $pixbuf->render_pixmap_and_mask_for_colormap ($colormap, $alpha_threshold)

$pixbuf->render_threshold_alpha ($bitmap, $src_x, $src_y, $dest_x, $dest_y, $width, $height, $alpha_threshold)

$pixbuf->render_to_drawable ($drawable, $gc, $src_x, $src_y, $dest_x, $dest_y, $width, $height, $dither, $x_dither, $y_dither)

$pixbuf->render_to_drawable_alpha ($drawable, $src_x, $src_y, $dest_x, $dest_y, $width, $height, $alpha_mode, $alpha_threshold, $dither, $x_dither, $y_dither)

pixbuf = $src->rotate_simple ($angle)

Since: gtk+ 2.6

integer = $pixbuf->get_rowstride

$src->saturate_and_pixelate ($dest, $saturation, $pixelate)

$pixbuf->save ($filename, $type, ...)

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.

scalar = $pixbuf->save_to_buffer ($type, ...)

Save $pixbuf to a scalar buffer, in the format $type, which is currently "jpeg" or "png". The function will croak if there is an error, which may arise from image format-related issues.

The returned string contains binary data, which may have embedded nuls. Don't try to print it.

See Gtk2::Gdk::Pixbuf::save for more details.

May croak with a Glib::Error in $@ on failure.

Since: gtk+ 2.4

$src->scale ($dest, $dest_x, $dest_y, $dest_width, $dest_height, $offset_x, $offset_y, $scale_x, $scale_y, $interp_type)

pixbuf or undef = $src->scale_simple ($dest_width, $dest_height, $interp_type)

integer = $pixbuf->get_width

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

enum Gtk2::Gdk::InterpType

enum Gtk2::Gdk::PixbufAlphaMode

enum Gtk2::Gdk::PixbufError

enum Gtk2::Gdk::PixbufRotation

enum Gtk2::Gdk::RgbDither

SEE ALSO

Gtk2, Glib::Object

COPYRIGHT

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

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


[Top] Generated by Marek::Pod::HTML 0.49 on Wed Dec 16 23:01:55 2009