MacArthur, Ian (SELEX GALILEO, UK) schrieb:
> of course.

Finally I found what causes my problem - it is because of the menu!
When I call my offscreen-drawing from a button, it works, when I call it 
from the menu, it fails "X_FreePixmap: BadPixmap (invalid Pixmap 
parameter) 0x340001e". This is easy to solve (timer), but was hard to 
find...

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
#include "write_png.h"

#include <w_time.h>

Fl_Window* pMW= 0;

void Cb_Bn(Fl_Widget* o, void* v)
{
        enum { ow= 400, oh= 400 };
        if (Fl_Offscreen OF=  fl_create_offscreen(ow, oh))
        {
                fl_begin_offscreen(OF);
                fl_rectf(0, 0, ow, oh, Fl_Color(w_time().Seconds()% 15));
                for (int i= 10; i< 100; i+= 10) fl_rect(i, i, ow -2*i, oh -2*i, 
Fl_Color(i%15));
                if (unsigned char* pImage= fl_read_image(0, 0, 0, ow, oh, 0))
                {       // Get image
                        write_png("/home/ed/temp/test.png", pImage, ow, oh, 3);
                        delete[] pImage;
                }
                fl_end_offscreen();
                fl_delete_offscreen(OF);
        }
}

int main()
{
        Fl_Window Win(100, 100, 640, 480, "Offscreen Image");
        pMW= &Win;
        Fl_Menu_Bar *pMenu= new Fl_Menu_Bar(0, 0, Win.w(), 25);
        pMenu->add("&Draw-Demo",0,0,0,FL_SUBMENU);
        pMenu->add("Draw-Demo/&Export", 0, Cb_Bn);

        Fl_Button* pB= new Fl_Button(10, 100, 100, 100, "&Export Png");
        Win.resizable(pMW);
        pB->callback(Cb_Bn, 0);
        pB->when(FL_WHEN_RELEASE);
        Win.end();
        Win.show();
        return Fl::run();
}
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to