Re: Rgba to pixbuf



Thanks, it is working. I reused some of your code:
http://cpansearch.perl.org/src/KRYDE/Image-Base-Gtk2-5/lib/Image/Base/Gtk2/Gdk/Pixbuf.pm

Currently my code looks like this:

my $pixbuf = Gtk2::Gdk::Pixbuf->new('rgb',1,8,$width,$height);

for(<iterate x-coordinate>){
for(<iterate y-coordinate>){
                #$r, $g, $b, $a at pixel x,y
my $data = pack ('C*', $r, $g, $b, $a);
my $src_pixbuf =
                        Gtk2::Gdk::Pixbuf->new_from_data(
                        $data, 'rgb', 1, 8, 1, 1, 4);    
$src_pixbuf->copy_area (0,0,1,1, $pixbuf, $x,$y);
}
}

The 'copy_area' part is very slow, because it creates a new pixbuf for
every single pixel and puts it on the final pixbuf. 

Is there any way to 'pack' all rgba values at once and use this packed
scalar to create the final pixbuf?





Am Dienstag, den 15.02.2011, 07:40 +1100 schrieb Kevin Ryde: 
Mario Kemper <mario kemper googlemail com> writes:

how do I convert rgba information into a pixbuf? I have an array with
rgba values (0-255) for each pixel. How do I need to pack those
information in order to use Gtk2::Gdk::Pixbuf->new_from_data?

Bytes in a string, eg. "\377\0\0" for a red pixel.  8 bits per component
is all that's supported.

There's no size check as yet on the width x height vs the length of the
byte string you supply, so be careful with that, and also make sure it's
a byte string not a utf8 wide-char string thingie.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]