Re: Colormaps in pixbufs which are in treeview
- From: muppet <scott asofyet org>
- To: zentara <zentara1 sbcglobal net>
- Cc: gtk-perl-list gnome org
- Subject: Re: Colormaps in pixbufs which are in treeview
- Date: Sat, 17 Feb 2007 18:30:32 -0500
On Feb 17, 2007, at 10:30 AM, zentara wrote:
Emmanuel's seems more useful since it takes $alpha values too.
(but maybe muppet can improve his to take alpha :-) )
Here you go. Not very different. Note that the row stride is now
$width * 4 instead of $width * 3.
sub create_solid_color_pixbuf_with_alpha {
my ($width, $height, $red, $green, $blue, $alpha) = @_;
my $data = pack "C*", ($red, $green, $blue, $alpha) x ($width *
$height);
return Gtk2::Gdk::Pixbuf->new_from_data ($data, 'rgb', TRUE, 8,
$width, $height, $width
* 4);
}
However, now that Emmanuel has gently reminded me of the existence of
fill(), i'd probably use that, because all of the work happens under
the hood.
Still, now that you know how to use pack() with the repeat operator
to fill with a color, it's just a short conceptual jump to
manipulating your image data in perl. For example:
sub create_solid_color_pixbuf_with_alpha_gradient {
my ($width, $height, $red, $green, $blue) = @_;
my $data = pack "C*",
map { ($red, $green, $blue, ($_ * 255.0 / ($height - 1))) x
$width }
0 .. ($height-1);
return Gtk2::Gdk::Pixbuf->new_from_data ($data, 'rgb', TRUE, 8,
$width, $height, $width * 4);
}
Now I feel like i deserve an award for egregious disregard for memory
efficiency. :-)
--
If the monkey could type one keystroke every nanosecond, the expected
waiting time until the monkey types out Hamlet is so long that the
estimated age of the universe is insignificant by comparison ... this
is not a practical method for writing plays.
-- Gian-Carlo Rota
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]