Re: How to use cairo with gtk




On Mar 21, 2008, at 9:59 AM, Ye Wenbin wrote:
Hi,
I try a new module VS::Chart which create chart using Cairo.
I want display the image as a Gtk widget without save the image
to disk. The problem is VS::Chart using Cairo::ImageSurface
to draw the chart, I can't find document for that.
Is it possible convert the Cairo::ImageSurface to Gtk2::Image?
I am especial appreciate if you can give some document
about the concepts in Gtk or Cairo, for example,
Gdk, graphic context, and so on. I'm not good at English,
so understanding these things is not easy for me.


The lack of a way to display cairo image surfaces directly through gtk + is a known deficiency in gtk+, last i heard.

The documentation for the cairo image surface is here:
http://cairographics.org/manual/cairo-Image-Surfaces.html

The perl API is pretty much the same; $imagesurface->get_data() returns you a scalar holding the image data. If you ensure that the cairo image surface is created in cairo's RGB24 format, you can use the data directly with Gtk2::Gdk::Pixbuf like this:


    my $width = $surface->get_width;
    my $height = $surface->get_height;
    my $stride = $surface->get_stride;
    my $data = $surface->get_data;

my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_data ($data, 'rgb', FALSE, 8, $wudth, $height, $stride);

    my $image = Gtk2::Image->new_from_pixbuf ($pixbuf);


--
zella (crying):  I want...
us:  What?
zella (still crying):  I want...  something!





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