Next: Gtk2::Gdk::PixbufAnimation | Previous: Gtk2::Gdk::PangoRenderer | [Gtk2-Perl - Table of Contents] | [Gtk2-Perl - Index] |
Gtk2::Gdk::Pixbuf
Glib::Object +----Gtk2::Gdk::Pixbuf
$colorspace (Gtk2::Gdk::Colorspace)
$has_alpha (boolean)
$bits_per_sample (integer)
$width (integer)
$height (integer)
$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).
May croak with a Glib::Error in $@ on failure.
May croak with a Glib::Error in $@ on failure.
Since: gtk+ 2.6
May croak with a Glib::Error in $@ on failure.
Since: gtk+ 2.4
$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.
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?]
Since: gtk+ 2.11
$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)
$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)
$dest_width (integer)
$dest_height (integer)
$interp_type (Gtk2::Gdk::InterpType)
$overall_alpha (integer)
$check_size (integer)
$color1 (unsigned)
$color2 (unsigned)
$src_x (integer)
$src_y (integer)
$width (integer)
$height (integer)
$dest_pixbuf (Gtk2::Gdk::Pixbuf)
$dest_x (integer)
$dest_y (integer)
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
Clear $pixbuf to contain only the value given in $pixel.
Since: gtk+ 2.6
Returns a list of hashes with information about the formats supported by Gtk2::Gdk::Pixbuf.
Since: gtk+ 2.2
$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.
$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.
$bitmap (Gtk2::Gdk::Bitmap)
$src_x (integer)
$src_y (integer)
$dest_x (integer)
$dest_y (integer)
$width (integer)
$height (integer)
$alpha_threshold (integer)
$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)
$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)
Since: gtk+ 2.6
$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.
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
$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)
'nearest' / 'GDK_INTERP_NEAREST'
'tiles' / 'GDK_INTERP_TILES'
'bilinear' / 'GDK_INTERP_BILINEAR'
'hyper' / 'GDK_INTERP_HYPER'
'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'
'none' / 'GDK_PIXBUF_ROTATE_NONE'
'counterclockwise' / 'GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE'
'upsidedown' / 'GDK_PIXBUF_ROTATE_UPSIDEDOWN'
'clockwise' / 'GDK_PIXBUF_ROTATE_CLOCKWISE'
Copyright (C) 2003-2008 by the gtk2-perl team.
This software is licensed under the LGPL. See Gtk2 for a full notice.