Bonjour,
J'ai 2 images dans une Vbox et je souhaite modifier une image en remplaçant certains de ces pixels par ceux de l'autre image.
Mon problème vient lors de l'actualisation des images.
Voici mon code
le main :
// Le fichier fonction.c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 #include <stdlib.h> #include <gtk/gtk.h> #include "fonction.h" int main(int argc, char **argv) { GtkWidget *pWindow; GtkWidget *pVBox; GtkWidget *pImage; GtkWidget *pImage_texture; GtkWidget * pbutton; Image_struc* image_st;image_st = g_malloc(sizeof(Image_struc)); /*initialisation de gtk*/ gtk_init(&argc, &argv); pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); /*La fenetre ne pourra pas etre redimmensionnable*/ gtk_window_set_resizable(GTK_WINDOW(pWindow),FALSE); /// Definition de la position gtk_window_set_position(GTK_WINDOW(pWindow), GTK_WIN_POS_CENTER); gtk_window_set_default_size(GTK_WINDOW(pWindow), 1024, 768); gtk_window_set_title(GTK_WINDOW(pWindow), "Ma fenetre"); g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL); pVBox = gtk_hbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(pWindow), pVBox); ///* Chargement des images a partir d'un fichier */ image_st->wid_image1=gdk_pixbuf_new_from_file_at_size("./image1.jpg",300,300,NULL); pImage = gtk_image_new_from_pixbuf(image_st->wid_image1); gtk_box_pack_start(GTK_BOX(pVBox), pImage, FALSE, FALSE, 5); // GdkPixbuf * image_charge=gdk_pixbuf_new_from_file_at_size("./image2.png",300,300,NULL); image_st->wid_image2=gdk_pixbuf_new_from_file_at_size("./tux.jpg",300,300,NULL); pImage_texture = gtk_image_new_from_pixbuf(image_st->wid_image2); gtk_box_pack_start(GTK_BOX(pVBox), pImage_texture, FALSE, FALSE, 5); pbutton=gtk_button_new_with_label("Action"); gtk_box_pack_start(GTK_BOX(pVBox), pbutton, FALSE, FALSE, 5); /// callback g_signal_connect (G_OBJECT(pbutton), "clicked", G_CALLBACK (remplir_image), (gpointer*)image_st); /*affichage de tout*/ gtk_widget_show_all(pWindow); /*fermeture de gtk*/ gtk_main(); return EXIT_SUCCESS; }
// Le fichier fonction.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 #include <stdlib.h> #include <gtk/gtk.h> #include "fonction.h" void put_pixel (GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green, guchar blue) { int width, height, rowstride, n_channels; guchar *pixels, *p; n_channels = gdk_pixbuf_get_n_channels (pixbuf); g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB); g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); //g_assert (gdk_pixbuf_get_has_alpha (pixbuf)); g_assert (n_channels == 3); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); g_assert (x >= 0 && x < width); g_assert (y >= 0 && y < height); rowstride = gdk_pixbuf_get_rowstride (pixbuf); pixels = gdk_pixbuf_get_pixels (pixbuf); p = pixels + y * rowstride + x * n_channels; p[0] = red; p[1] = green; p[2] = blue; //p[3] = alpha; } gboolean gdkpixbuf_get_colors_by_coordinates(GdkPixbuf *pixbuf, gint x, gint y, guchar *red, guchar *green, guchar *blue) { guchar *pixel=NULL; gint channel=0; gint width=0; if (!pixbuf) return FALSE; if (x<0 || y<0) return FALSE; if (x>gdk_pixbuf_get_width(pixbuf)) return FALSE; if (y>gdk_pixbuf_get_height(pixbuf)) return FALSE; pixel=gdk_pixbuf_get_pixels(pixbuf); channel=gdk_pixbuf_get_n_channels(pixbuf); width=gdk_pixbuf_get_width(pixbuf); *red = pixel[(x*channel)+(y*width*channel)]; *green = pixel[(x*channel)+(y*width*channel)+1]; *blue = pixel[(x*channel)+(y*width*channel)+2]; return TRUE; } void remplir_image(GtkWidget *pButton, gpointer data){ Image_struc* image_st; image_st=(Image_struc*) data; GdkPixbuf* image_texture_buf=image_st->wid_image1; GdkPixbuf *image_charge=image_st->wid_image2; guchar rouge, vert, bleu; gint x;gint y; for (x=0;x<2;x++) { for (y=0;y<5;y++) { g_print("ici x= %d",x); g_print(" ici y= %d\n",y); gdkpixbuf_get_colors_by_coordinates(image_texture_buf,x,y,&rouge, &vert, &bleu); put_pixel(image_charge, x,y,rouge,vert,bleu); } } }
Peut-etre que le problème vient du fait que j'utilise des GdkPixbuf comme intermédiaire...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 void put_pixel (GdkPixbuf *pixbuf, int x, int y, guchar red, guchar green, guchar blue); gboolean gdkpixbuf_get_colors_by_coordinates(GdkPixbuf *pixbuf, gint x, gint y, guchar *red, guchar *green, guchar *blue); void remplir_image(GtkWidget *pButton, gpointer data); typedef struct { GdkPixbuf *wid_image1; GdkPixbuf *wid_image2; GtkWidget *GtkWidget_1; GtkWidget *GtkWidget_2; } Image_struc;
Merci de votre aide.
Partager