1
我想將我的pixbuf轉換爲「GtkSelectionData」,那麼,如何將它轉換爲C++? 以下是我的示例代碼。想要將「GdkPixbuf」轉換爲「GtkSelectionData」對象
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default(),
GDK_SELECTION_CLIPBOARD);
GdkPixbuf *pixbuf;
pixbuf = gtk_clipboard_wait_for_image (clipboard);
if (pixbuf != NULL)
{
int width, height;
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
//printf("width : %d", width);
GtkSelectionData *selectionData;
gtk_selection_data_set_pixbuf(selectionData,pixbuf);
g_object_unref (pixbuf);
}
Error: cannot convert ‘GdkPixbuf* {aka _GdkPixbuf*}’ to ‘GtkSelectionData* {aka _GtkSelectionData*}’ in initialization
感謝,Jimit
@Trishtan我正在複製一個圖像並將其轉換到pixbuf中,我想將該pixbuf轉換爲「GtkSelectionData」對象。上面的函數將幫助我得到相同的結果嗎? – Jimit
'GtkSelectionData'是一個結構,它包含一個指向要傳輸的數據的指針,以及類型和大小等其他元數據。上述函數將pixbuf指針存儲在選擇數據結構中,告訴GTK「這是我想要傳輸的原始數據」。但是您首先需要通過GTK回調交付選擇數據,因此所有其他元數據都已正確填寫。你很少需要自己創建一個'GtkSelectionData'。 –
我修改了上面的代碼。你可以看看它嗎? – Jimit