Re: Pixbuf to Cairo and vice versa



On 13.07.2011 15:41, Mario Kemper wrote:
3) Show the final image in a widget, i.e. convert the cairo surface back to a pixbuf

#write surface to pixbuf
my $loader = Gtk2::Gdk::PixbufLoader->new;
$surface->write_to_png_stream(
        sub {
                my ( $closure, $data ) = @_;
                $loader->write($data);
        }
);
$loader->close;

<<<  use $loader->get_pixbuf somewhere>>>

Maybe this approach is faster: <http://lethalman.blogspot.com/2009/04/create-pixbuf-from-cairo-surface.html>?

Alternatively, if all you want is to display the altered image, then you could write a custom widget that uses the gdk and cairo integration stuff to draw the surface. Like described here: <http://gnomejournal.org/article/34/writing-a-widget-using-cairo-and-gtk28>, or as is done here: <http://api.metacpan.org/source/TSCH/Gtk2-1.224/examples/cairo-rendering.pl>. Use Cairo::set_source_surface to copy your surface into the widget's surface.



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