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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| #include <stdlib.h>
#include <gtk/gtk.h>
void OnZoomIn(GtkWidget *pWidget, gpointer data);
void OnZoomOut(GtkWidget *pWidget, gpointer data);
void cassetoi(GtkWidget *pWidget, gpointer data);
gboolean gdkpixbuf_get_colors_by_coordinates(GdkPixbuf *pixbuf, gint x, gint y, guchar *red, guchar *green, guchar *blue);
int main(int argc, char **argv)
{
GtkWidget *pWindow;
GtkWidget *pBox;
GtkWidget *pBox2;
GtkWidget *pZoomIn;
GtkWidget *pZoomOut;
GtkWidget *cassepixel;
GtkWidget *pScrolled;
GtkWidget *pImage;
gtk_init(&argc, &argv);
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(pWindow), 500, 500);
g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
pBox = gtk_vbox_new(FALSE, 5);
gtk_container_add(GTK_CONTAINER(pWindow), pBox);
pBox2 = gtk_hbox_new(TRUE, 5);
gtk_box_pack_start(GTK_BOX(pBox), pBox2, FALSE, FALSE, 0);
pZoomIn = gtk_button_new_from_stock(GTK_STOCK_ZOOM_IN);
gtk_box_pack_start(GTK_BOX(pBox2), pZoomIn, TRUE, TRUE, 0);
pZoomOut = gtk_button_new_from_stock(GTK_STOCK_ZOOM_OUT);
gtk_box_pack_start(GTK_BOX(pBox2), pZoomOut, TRUE, TRUE, 0);
cassepixel = gtk_button_new_with_label("cassepixel");
gtk_box_pack_start(GTK_BOX(pBox2), cassepixel, TRUE, TRUE, 0);
pScrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_box_pack_start(GTK_BOX(pBox), pScrolled, TRUE, TRUE, 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(pScrolled), GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
pImage = gtk_image_new_from_file("imagedetest.png");
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(pScrolled), pImage);
g_signal_connect(G_OBJECT(pZoomIn), "clicked", G_CALLBACK(OnZoomIn), pImage);
g_signal_connect(G_OBJECT(pZoomOut), "clicked", G_CALLBACK(OnZoomOut), pImage);
g_signal_connect(G_OBJECT(cassepixel), "clicked", G_CALLBACK(cassetoi), pImage);
gtk_widget_show_all(pWindow);
gtk_main();
return EXIT_SUCCESS;
}
void OnZoomIn(GtkWidget *pWidget, gpointer data)
{
GdkPixbuf *pSrcPixbuf, *pDestPixbuf;
gint iWidth, iHeight;
// Recuperation du GdkPixbuf //
pSrcPixbuf = gtk_image_get_pixbuf(GTK_IMAGE(data));
// Recuperation de la taille de l'image //
iWidth = gdk_pixbuf_get_width(pSrcPixbuf);
iHeight = gdk_pixbuf_get_height(pSrcPixbuf);
// Creation du nouveau GdkPixbuf //
pDestPixbuf = gdk_pixbuf_scale_simple(pSrcPixbuf, iWidth+10, iHeight+10, GDK_INTERP_NEAREST);
// Remplacement de l'ancien GdkPixbuf par le nouveau //
gtk_image_set_from_pixbuf(GTK_IMAGE(data), pDestPixbuf);
g_object_unref(pDestPixbuf);
}
void OnZoomOut(GtkWidget *pWidget, gpointer data)
{
GdkPixbuf *pSrcPixbuf, *pDestPixbuf;
gint iWidth, iHeight;
// Recuperation du GdkPixbuf //
pSrcPixbuf = gtk_image_get_pixbuf(GTK_IMAGE(data));
// Recuperation de la taille de l'image //
iWidth = gdk_pixbuf_get_width(pSrcPixbuf);
iHeight = gdk_pixbuf_get_height(pSrcPixbuf);
// Creation du nouveau GdkPixbuf //
pDestPixbuf = gdk_pixbuf_scale_simple(pSrcPixbuf, iWidth-10, iHeight-10, GDK_INTERP_NEAREST);
// Remplacement de l'ancien GdkPixbuf par le nouveau //
gtk_image_set_from_pixbuf(GTK_IMAGE(data), pDestPixbuf);
g_object_unref(pDestPixbuf);
}
void cassetoi(GtkWidget *pWidget, gpointer data)
{
GdkPixbuf *pSrcPixbuf, *pDestPixbuf;
gint iWidth, iHeight;
// Recuperation du GdkPixbuf //
pSrcPixbuf = gtk_image_get_pixbuf(GTK_IMAGE(data));
guchar *red=NULL, *green=NULL, *blue=NULL;
gint x=0,y=0;
guchar *putaindepixel=gdkpixbuf_get_colors_by_coordinates(pSrcPixbuf, x, y,red,green,blue);
// Remplacement de l'ancien GdkPixbuf par le nouveau //
gtk_image_set_from_pixbuf(GTK_IMAGE(data), pDestPixbuf);
g_object_unref(pDestPixbuf);
}
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;
} |
Partager