|
i get segmentation fault in this command:
g_object_set(image, "pixbuf", new_pixbuf, NULL);
why why why?
javascript:emoticon(':('), thanks
[code=]
#include <gtk/gtk.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <string.h>
int resized;
/* standard handlers */
gint delete_event(GtkWidget *widget, GdkEvent event, gpointer data)
{
return FALSE;
}
void end_program(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
void render_image(GtkWidget *window, gpointer data)
{
GtkImage *image;
GtkButton *button;
GdkPixbuf *orig_pixbuf, *new_pixbuf;
gint orig_width, orig_height;
gint new_width, new_height;
gdouble zoom_value;
if(resized!=0 && resized%2==0){
image = (GtkImage *) data;
/* get the original pixbuf dimensions */
orig_pixbuf = (GdkPixbuf *)g_object_get_data(G_OBJECT(image), "orig−pixbuf");
orig_width = gdk_pixbuf_get_width(orig_pixbuf);
orig_height = gdk_pixbuf_get_height(orig_pixbuf);
/* get adjuster−induced changes */
zoom_value = 2;
/* compute new size */
new_width = (gint)(orig_width * zoom_value);
new_height = (gint)(orig_height * zoom_value);
/* prevent a height or width of 0 */
new_width = MAX(1, new_width);
new_height = MAX(1, new_height);
/* scale the original pixbuf to the new dimensions
(feel free to try other interpolation algorithms) */
new_pixbuf = gdk_pixbuf_scale_simple(orig_pixbuf,
new_width,
new_height,
GDK_INTERP_BILINEAR);
/* display the new pixbuf in the image widget */
g_object_set(image, "pixbuf", new_pixbuf, NULL);
/* reference to new_pixbuf is no longer necessary,
the system may dispose of it when convenient */
g_object_unref(new_pixbuf);
}
resized++;
}
int main(int argc, char **argv)
{
GtkWindow *window;
GtkHBox *hbox;
GtkImage *image;
GtkVBox *zoom_box, *saturation_box;
GtkButton *button;
GtkLabel *label;
GtkVScale *zoom_slider, *saturation_slider;
GtkAdjustment *zoom, *saturation;
GdkPixbuf *orig_pixbuf;
resized=0;
/* initialize GTK+, create a window */
gtk_init(&argc, &argv);
window = g_object_new(GTK_TYPE_WINDOW,"title", "resize 2","default−width", 300,"default−height", 300,"border−width", 12,NULL);
/* attach standard event handlers */
g_signal_connect(window, "delete_event", G_CALLBACK(delete_event), NULL);
g_signal_connect(window, "destroy", G_CALLBACK(end_program), NULL);
/* create image widget and load a file */
image = g_object_new(GTK_TYPE_IMAGE, "file", "sÃ.jpg", NULL);
/* store the original pixbuf in the image widget data */
g_object_get(image, "pixbuf", &orig_pixbuf, NULL);
g_object_set_data(G_OBJECT(image), "orig−pixbuf", (gpointer)orig_pixbuf);
g_object_set(button, "image", image, NULL);
/* install adjuster signal handlers */
g_signal_connect(GTK_WIDGET(window), "size-request",
G_CALLBACK(render_image), (gpointer) image);
/* create a new HBox, pack the image and vboxes above */
hbox = g_object_new(GTK_TYPE_HBOX, NULL);
gtk_box_pack_start_defaults(GTK_BOX(hbox), GTK_WIDGET(image));
/* pack everything into the window, show everything, start GTK+ main loop */
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(hbox));
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
[/code]
|