on DrawingArea, pixmap and pixbuf
- From: David Eduardo Gomez Noguera <davidgn servidor unam mx>
- To: GTK-list <gtk-list gnome org>
- Subject: on DrawingArea, pixmap and pixbuf
- Date: 20 Apr 2002 11:25:04 -0600
Hello.
browsing the scribble source code, i see that it creates the pixmap used
in the callbacks, and that its a global.
My program creates the pixmap on the main() function, but when passing
drawing_area->window, the compiled program tells of "Gdk-CRITICAL **:
file gdkpixmap.c: line 62 (gdk_pixmap_new): assertion `(window != NULL)
|| (depth != -1)' failed.", so drawing_area->window is null.
why does it happens? is it because its outside the gtk_main() thread?
it doesnt happen if i pass mainwindow->window.
also, i pass -1 as depth.
later on, a call to gdk_pixbuf_get_from_drawable and to
gdk_pixbuf_get_bits_per_sample returns an 8.
Ive done all this to create a png from the GdkPixmap.
the code to make the png is:
/*********************/
GtkWidget *area;
GdkPixmap *pixmap;
GdkPixbuf *pixbuf;
GdkDrawable *drawable;
gint bpp;
guchar *buffer;
FILE *imagen;
png_structp png_ptr;
png_infop info_ptr;
png_uint_32 k;
png_bytep row_pointers[ALTO];
area = gtk_object_get_data(GTK_OBJECT(user_data), "dibujo");
pixmap = gtk_object_get_data(GTK_OBJECT(area), "mapa");
drawable = pixmap;
pixbuf =
gdk_pixbuf_get_from_drawable(NULL, drawable,
gtk_widget_get_colormap(user_data), 0,
0, 0, 0, 100, 100);
imagen=fopen("imagen.png","wb");
bpp = gdk_pixbuf_get_bits_per_sample(pixbuf);
printf("%d\n", bpp);
buffer = gdk_pixbuf_get_pixels(pixbuf);
png_ptr = png_create_write_struct
(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
return (ERROR);
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
return (ERROR);
}
if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(imagen);
return (ERROR);
}
png_init_io(png_ptr, imagen);
png_set_IHDR(png_ptr, info_ptr, ANCHO, ALTO, bpp,
PNG_COLOR_TYPE_RGB,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);
for (k = 0; k < ALTO; k++)
row_pointers[k] = buffer + k*ANCHO*3;
png_write_image(png_ptr, row_pointers);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(imagen);
/**************************/
I am using Gtk+ 1.4
What am i doing wrong? some values i am just gessing (like k*ANCHO*3).
Any suggestions, corrections?
Note: ANCHO=width ALTO=height
--
ICQ: 15605359 Bicho
=^..^=
First, they ignore you. Then they laugh at you. Then they fight you.
Then you win. Mahatma Gandhi.
-------------------------------気検体の一致------------------------------------
暑さ寒さも彼岸まで。
恋にししょうなし。恋はしあんの他。
アン アン アン とっても大好き
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]