Re: gtk_clipboard_set_image




On Thu, Nov 4, 2010 at 8:22 PM, Lex Trotman <elextr gmail com> wrote:
On 4 November 2010 19:44, Andy Bell <andy bell allbabel com> wrote:
> On Wed, Nov 3, 2010 at 11:46 PM, Lex Trotman <elextr gmail com> wrote:
>>
>> On 3 November 2010 21:19, Andy Bell <andy bell allbabel com> wrote:
>> > Hi All,
>> >
>> > I am having trouble with setting an image to the clipboard.
>> >
>> > I receive image data which I write out to disk and then create a
>> > GdkPixbuf
>> > from that, which I then store to the clipboard.
>> >
>> > My code is as follows:
>> >
>> > GError * error = NULL;
>> > GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file( "/tmp/test.jpg", &error
>> > );
>> > if ( pixbuf != NULL && error == NULL )
>> > {
>> >     gtk_clipboard_set_image( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD
>> > ),
>> > pixbuf );
>> >     gtk_clipboard_store( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ) );
>> >     gdk_pixbuf_unref( pixbuf );
>> > }
>> > unlink(  "/tmp/test.jpg" );
>> >
>> > I don't get any errors, but when I come to try to paste it I have
>> > nothing on
>> > the clipboard.  For example, opening OpenOffice, I would like to paste
>> > the
>> > image but nothing happens, nor in GIMP.  I am using Ubuntu 10.4.
>>
>> I guess its too obvious to say that the pixbuf_new_from_file failed,
>> but did you check with a debugger or try adding an "else rude message"
>> clause?.
>>
>
> It works, I even check it with gtk_clipboard_wait_is_image_available and
> that returns true!  When I come back to get the image from the clipboard in
> the same application on an event using gtk_clipboard_wait_is_image_available
> it returns false.  Does the image have a life span or something?  Does it
> need to remain referenced in the application?

Well clipboard_set_image doesn't say it takes a copy, but I would have
expected it to take a reference. Have you set can_store for images (or
all)?

 
I thought the following stored it to the clipboard: 
gtk_clipboard_store( gtk_clipboard_get( GDK_SELECTION_CLIPBOARD ) );

I had thought it had something to do with threads but I am now looking at the fact that it could be something else.  This application is a CLI, I am not sure if that has anything to do with it but a simple test CLI works fine using threads.  I am being passed data from an Air application which has full screen display and I am not sure whether there is something else going on in the background.

Thanks, Andy


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