Provided by: libgtk2-perl-doc_1.249-2_all
NAME
Gtk2::Gdk::Pixbuf - wrapper for GdkPixbuf
HIERARCHY
Glib::Object +----Gtk2::Gdk::Pixbuf
INTERFACES
Glib::Object::_Unregistered::GIcon Glib::Object::_Unregistered::GLoadableIcon
METHODS
pixbuf = Gtk2::Gdk::Pixbuf->new ($colorspace, $has_alpha, $bits_per_sample, $width, $height) • $colorspace (Gtk2::Gdk::Colorspace) • $has_alpha (boolean) • $bits_per_sample (integer) • $width (integer) • $height (integer) pixbuf = Gtk2::Gdk::Pixbuf->new_from_data ($data, $colorspace, $has_alpha, $bits_per_sample, $width, $height, $rowstride) • $data (scalar) packed binary pixel data, usually made with pack() • $colorspace (Gtk2::Gdk::Colorspace) • $has_alpha (boolean) true if the image data includes an alpha channel (opacity information). • $bits_per_sample (integer) • $width (integer) in pixels. • $height (integer) in pixels. • $rowstride (integer) distance in bytes between row starts; usually 3*width for rgb data, 4*width if $has_alpha is true. 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) • $filename (localized file name) May croak with a Glib::Error in $@ on failure. pixbuf = Gtk2::Gdk::Pixbuf->new_from_file_at_scale ($filename, $width, $height, $preserve_aspect_ratio) • $filename (localized file name) • $width (integer) • $height (integer) • $preserve_aspect_ratio (boolean) 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) • $filename (localized file name) • $width (integer) • $height (integer) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.4 pixbuf = Gtk2::Gdk::Pixbuf->new_from_inline ($data, $copy_pixels=TRUE) • $data (scalar) packed binary data, the format is special, see discussion • $copy_pixels (boolean) whether $data should be copied, defaults to 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 (...) • ... (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. "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) • $src_x (integer) • $src_y (integer) • $width (integer) • $height (integer) pixbuf = $pixbuf->add_alpha ($substitute_color, $r, $g, $b) • $substitute_color (boolean) • $r (Glib::UChar) • $g (Glib::UChar) • $b (Glib::UChar) 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) • $dest (Gtk2::Gdk::Pixbuf) • $dest_x (integer) • $dest_y (integer) • $dest_width (integer) • $dest_height (integer) • $offset_x (double) • $offset_y (double) • $scale_x (double) • $scale_y (double) • $interp_type (Gtk2::Gdk::InterpType) • $overall_alpha (integer) $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) • $dest (Gtk2::Gdk::Pixbuf) • $dest_x (integer) • $dest_y (integer) • $dest_width (integer) • $dest_height (integer) • $offset_x (double) • $offset_y (double) • $scale_x (double) • $scale_y (double) • $interp_type (Gtk2::Gdk::InterpType) • $overall_alpha (integer) • $check_x (integer) • $check_y (integer) • $check_size (integer) • $color1 (unsigned) • $color2 (unsigned) pixbuf or undef = $src->composite_color_simple ($dest_width, $dest_height, $interp_type, $overall_alpha, $check_size, $color1, $color2) • $dest_width (integer) • $dest_height (integer) • $interp_type (Gtk2::Gdk::InterpType) • $overall_alpha (integer) • $check_size (integer) • $color1 (unsigned) • $color2 (unsigned) pixbuf = $pixbuf->copy $src_pixbuf->copy_area ($src_x, $src_y, $width, $height, $dest_pixbuf, $dest_x, $dest_y) • $src_x (integer) • $src_y (integer) • $width (integer) • $height (integer) • $dest_pixbuf (Gtk2::Gdk::Pixbuf) • $dest_x (integer) • $dest_y (integer) (format, width, height) = $pixbuf->get_file_info ($filename) • $filename (localized file name) 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) • $pixel (unsigned) a packed RGBA value. Clear $pixbuf to contain only the value given in $pixel. pixbuf = $src->flip ($horizontal) • $horizontal (boolean) 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) • $src (Gtk2::Gdk::Drawable) • $cmap (Gtk2::Gdk::Colormap or undef) • $src_x (integer) • $src_y (integer) • $dest_x (integer) • $dest_y (integer) • $width (integer) • $height (integer) 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) • $src (Gtk2::Gdk::Image) • $cmap (Gtk2::Gdk::Colormap or undef) • $src_x (integer) • $src_y (integer) • $dest_x (integer) • $dest_y (integer) • $width (integer) • $height (integer) 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) • $key (string) boolean = $pixbuf->set_option ($key, $value) • $key (string) • $value (string) Since: gtk+ 2.2 scalar = $pixbuf->get_pixels Return a copy of the bytes comprising the pixel data of $pixbuf. As described in the Gdk Pixbuf reference manual (the "Note" section of "The GdkPixbuf Structure"), the last row does not extend to the rowstride, but ends with the last byte of the last pixel. The length of the "get_pixels" return reflects this. pixmap = $pixbuf->render_pixmap_and_mask ($alpha_threshold) (pixmap, mask) = $pixbuf->render_pixmap_and_mask ($alpha_threshold) • $alpha_threshold (integer) pixmap = $pixbuf->render_pixmap_and_mask_for_colormap ($colormap, $alpha_threshold) (pixmap, mask) = $pixbuf->render_pixmap_and_mask_for_colormap ($colormap, $alpha_threshold) • $colormap (Gtk2::Gdk::Colormap) • $alpha_threshold (integer) $pixbuf->render_threshold_alpha ($bitmap, $src_x, $src_y, $dest_x, $dest_y, $width, $height, $alpha_threshold) • $bitmap (Gtk2::Gdk::Bitmap) • $src_x (integer) • $src_y (integer) • $dest_x (integer) • $dest_y (integer) • $width (integer) • $height (integer) • $alpha_threshold (integer) $pixbuf->render_to_drawable ($drawable, $gc, $src_x, $src_y, $dest_x, $dest_y, $width, $height, $dither, $x_dither, $y_dither) • $drawable (Gtk2::Gdk::Drawable) • $gc (Gtk2::Gdk::GC) • $src_x (integer) • $src_y (integer) • $dest_x (integer) • $dest_y (integer) • $width (integer) • $height (integer) • $dither (Gtk2::Gdk::RgbDither) • $x_dither (integer) • $y_dither (integer) $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) • $drawable (Gtk2::Gdk::Drawable) • $src_x (integer) • $src_y (integer) • $dest_x (integer) • $dest_y (integer) • $width (integer) • $height (integer) • $alpha_mode (Gtk2::Gdk::PixbufAlphaMode) • $alpha_threshold (integer) • $dither (Gtk2::Gdk::RgbDither) • $x_dither (integer) • $y_dither (integer) pixbuf = $src->rotate_simple ($angle) • $angle (Gtk2::Gdk::PixbufRotation) Since: gtk+ 2.6 integer = $pixbuf->get_rowstride $src->saturate_and_pixelate ($dest, $saturation, $pixelate) • $dest (Gtk2::Gdk::Pixbuf) • $saturation (double) • $pixelate (boolean) $pixbuf->save ($filename, $type, ...) • $filename (localized file name) • $type (string) name of file format (e.g. "jpeg", "png") • ... (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. scalar = $pixbuf->save_to_buffer ($type, ...) • $type (string) name of file format (e.g. "jpeg", "png") • ... (list) list of key-value save options 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) • $dest (Gtk2::Gdk::Pixbuf) • $dest_x (integer) • $dest_y (integer) • $dest_width (integer) • $dest_height (integer) • $offset_x (double) • $offset_y (double) • $scale_x (double) • $scale_y (double) • $interp_type (Gtk2::Gdk::InterpType) pixbuf or undef = $src->scale_simple ($dest_width, $dest_height, $interp_type) • $dest_width (integer) • $dest_height (integer) • $interp_type (Gtk2::Gdk::InterpType) integer = $pixbuf->get_width
PROPERTIES
'bits-per-sample' (integer : default 8 : readable / writable / construct-only / private) The number of bits per sample 'colorspace' (Gtk2::Gdk::Colorspace : default "rgb" : readable / writable / construct-only / private) The colorspace in which the samples are interpreted 'has-alpha' (boolean : default false : readable / writable / construct-only / private) Whether the pixbuf has an alpha channel 'height' (integer : default 1 : readable / writable / construct-only / private) The number of rows of the pixbuf 'n-channels' (integer : default 3 : readable / writable / construct-only / private) The number of samples per pixel 'pixels' (gpointer : default 0 : readable / writable / construct-only / private) A pointer to the pixel data of the pixbuf 'rowstride' (integer : default 1 : readable / writable / construct-only / private) The number of bytes between the start of a row and the start of the next row 'width' (integer : default 1 : 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-2011 by the gtk2-perl team. This software is licensed under the LGPL. See Gtk2 for a full notice.