Re: How to use cairo with gtk



On Sat, 22 Mar 2008 10:06:22 +0800
"Ye Wenbin" <wenbinye gmail com> wrote:

On Sat, 22 Mar 2008 07:15:06 +0800, muppet <scott asofyet org> wrote:
Thank you very much!
I was told to use cairo_set_source_surface function, that works.
I paste my code here, in case somebody has the same question.

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);

Also I try this way, but it seems weird, the window is black.
the document of  gdk_pixbuf_new_from_data says "only RGB images with 8
bits per sample are supported", is it the reason?
Any way, thanks again for the help.

Hey, I was just fooling around with this today, and found something interesting.
The method of getting the pixbuf above, worked, but gave me interference vertical lines
in the saved file.... it is shown in the first attachment called pixbuf1.

But I found that if I used an old tip by Aristotle, to load the pixbuf, it saved fine, and
it allowed the argb32 to be used in the Cairo. The pixbuf loader seemed to load
it automatically in a correct manner. It saved fine and is in the second attachment
called pixbuf.

I found that if I used $surface->get_data  it was much more error prone, than if I used
the  $surface->write_to_png_stream

Anyways, maybe  $surface->write_to_png_stream is better for grabbing a pixbuf.


zentara


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Attachment: pixpuf1
Description: Binary data

Attachment: pixpuf
Description: Binary data



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