Re: getting color from gdk::pixbuf
- From: muppet <scott asofyet org>
- To: Domsodi Gergely <doome uhulinux hu>
- Cc: gtk-perl mailing list <gtk-perl-list gnome org>
- Subject: Re: getting color from gdk::pixbuf
- Date: 02 Mar 2004 15:02:23 -0500
On Tue, 2004-03-02 at 06:56, Domsodi Gergely wrote:
Hi!
I have a Gdk::Pixbuf (got it from a .png file) in a Gtk2::Image.
I want to get colors of specific pixels of this image, and give it to a
Gtk2::Gdk::Color so that I can draw with that color to a
Gtk2::Gdk::Pixmap.
How can I do this?
use $pixbuf->get_pixels to fetch the rgb image data as a packed scalar,
and then use unpack() or substr() to extract the pixels you want. not
very efficient for large pixbufs, but perl isn't meant for bit-banging.
#
# warning, untested code, watch for falling bullshit
#
$pixels = $pixbuf->get_pixels;
# n_channels should be 3 for rgb data, and 4 if there is alpha data.
$depth = $pixbuf->get_n_channels;
$offset = $row * $pixbuf->get_rowstride + $col * $depth;
($r, $g, $b, $a) = unpack "C*",
substr $pixels, $offset, $depth;
# $a will be undefined if $depth is 3.
# $[rgb] will be on the range [0-255] --- bitshift them left by 8
# for use with a Gtk2::Gdk::Color (to put them in the range
# [0-65535]).
--
muppet <scott at asofyet dot org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]