Hi Rodrigo, I haven't got a working Linux setup at the moment, but I compiled your code using FLTK 1.1.9 and the following command fltk-config --compile pnmtest.cxx
under Windows Vista using MSys/MinGW (gcc 3.4.5) and it works fine. The fltk-config command resulted in the following (actual) compiler command g++ -I/usr/local/include -I/usr/local/include/FL/images -mwindows -DWIN32 -mno-cygwin -o pnmtest pnmtest.cxx -mwindows -mno-cygwin /usr/local/lib/libfltk.a -lole32 -luuid -lcomctl32 -lwsock32 BrianT ----- Original Message ----- From: "Rodrigo Morante" <[email protected]> To: <[email protected]> Sent: Thursday, August 13, 2009 8:04 PM Subject: [fltk.general] Problem with fl_read_image Hi all. I wrote a widget that, when asked, dumps itself, so to speak, into a PNM. This works fine if I invoke its pnm-save method when the main window is exiting (by clicking the window's cross or Esc-aping). If I use first a Fl_File_Chooser (the way I intended to use more often) or even if I quit the program via an item in a Fl_Menu, all I got is garbage. I have prepared a little example that replicates this behaviour. I'm using Ubuntu 8.10 and 9.04, FLTK 1.1.9 (compiled by me). In Windows a similar problem arises. I even tried show()ing the window before using fl_read_image, to no avail. The error is: X_GetImage: BadDrawable (invalid Pixmap or Window parameter) 0x7400006 To compile this example: g++ pnmtest.cpp -lfltk -o pnmtest The code: // Begin pnmtest.cpp #include <FL/Fl.H> #include <FL/Fl_Double_Window.H> #include <FL/Fl_Button.H> #include <FL/fl_draw.H> #include <FL/Fl_File_Chooser.H> #include <stdlib.h> #include <stdio.h> int save_pnm(const char *name, Fl_Double_Window *win){ FILE *fp; if ((fp = fopen(name, "w+")) == 0) { perror("open"); exit(1); } uchar *buf = (uchar*)malloc(3*win->w()*win->h()*sizeof(uchar)); fl_read_image(buf, 0, 0, win->w(), win->h()); fprintf(fp, "P6\n%d %d\n255\n", win->w(), win->h()); fwrite((unsigned char *)buf, win->w() * win->h() * 3, 1, fp); fclose(fp); free(buf); return 0; } void wincb(Fl_Widget*, void *w){ Fl_Double_Window *win = (Fl_Double_Window*)w; save_pnm("fig.pnm", win); exit(0); return; } void btncb(Fl_Widget*, void *w){ Fl_Double_Window *win = (Fl_Double_Window*)w; Fl_File_Chooser chooser(".", "*.pnm", Fl_File_Chooser::CREATE, "Save as PNM"); chooser.show(); while(chooser.shown()) Fl::wait(); if (chooser.value() != NULL){ win->show(); Fl::check(); save_pnm(chooser.value(), win); } return; } int main(int argc, char *argv[]){ Fl_Double_Window win(10, 10, 200, 100, "Test"); Fl_Button btn(10, 10, win.w() - 20, win.h() - 20, "Save as PNM"); btn.callback(btncb, &win); win.end(); win.callback(wincb, &win); win.show(); return Fl::run(); } // End pnmtest.cpp Thanks to all, Rodrigo _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk -------------------------------------------------------------------------------- No virus found in this incoming message. Checked by AVG - www.avg.com Version: 8.5.392 / Virus Database: 270.13.54/2300 - Release Date: 08/13/09 06:11:00 _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

