[gtkmm] Example for Gdk::Pixbuf::create_from_data(...)



Hi

I am having trouble to get pixel data from an array into a
Gdk::Pixbuf and need an example. I am trying to define a
button that will create an all white 400x300 pixel buffer when
clicked on (this will emerge into several buttons that apply
different filters to an image eventually).

// somewhere in the Gui class constructor, I have:

const guint8 size = 400*300*3;
guint8 *workbuffer = new guint8 [size];


// the callback function:

void Gui::frequency_clicked() {
  for(int i=0; i<size; i++) {
    workbuffer[i]=255;  // all white pic, no alpha
  }
... // here the buffer shall be created
}

Now I wwould like to call create_from_data with something like
the following destroy slot (read that somewhere):

void pixbuf_cleanup(const guint8* data) {
  delete [] data;
}

How would the corresponding
buf_current = Gdk::Pixbuf::create_from_data(...);
call look, so that my workbuffer exists as long as it has to and
then gets destroyed properly? And, are the code fragments above
correct, especially the dynamic creation of a buffer in the
constructor?

I admit, maybe this is obvious and I just lack some basic C++
skills, but help is still appreciated! :)

Thanks in advance, t.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]