[Gtk-sharp-list] Images as buttons

Ramin Zabih rdz@cs.cornell.edu
Mon, 18 Aug 2003 00:53:48 -0400


I'm writing an image-processing application using gtk-sharp, hopefully =
to run under Linux and Windows. I'd like to have a table of image =
thumbnails, where the user can click on different thumbnails to select =
them and then process the selected images. My current idea is to create =
a table of buttons, where for each button b I call b.Add(image) with =
image a Gtk.Image (created from a Pixbuf). This seems to work, and by =
doing=20
	b.Clicked +=3D new EventHandler (callback);
I can cause the function callback to be executed each time b is clicked.

My question is how to efficiently change the thumbnail when the user =
clicks on it. I can get my hands on the original Pixbuf from callback, =
but I would like to use unsafe code for efficiency, and I'd like to be =
able to modify the raw bytes.  Here is my current attempt, based on code =
that works in C# with Systems.Windows.Forms:

                 Gtk.Image image =3D (Gtk.Image)child;
                 Gdk.Pixbuf pixbuf =3D image.Pixbuf;
                 System.IntPtr ptr =3D pixbuf.Handle;
                 int stride =3D pixbuf.Rowstride;
                 unsafe {
                   byte *p =3D (byte *)(void *)ptr;
                   int nWidth =3D pixbuf.Width*3;
                   int nHeight =3D pixbuf.Height;
                   int nOffset =3D stride - nWidth;
                       =20
                   for (int y =3D 0; y < nHeight;++y)
                     {
                       for (int x=3D0; x < nWidth; ++x )
                         {
                                p[0] =3D (byte)(255-p[0]);
                                ++p;
                          }
                        p +=3D nOffset;
                      }
                   }

Does anyone know the right way to do this? The code above does not =
work... Alternatively, is there an efficient way (i.e., without copying =
image arrays) to invoke a C DLL on the raw bytes?

Thanks,
Ramin