[gtkmm] displaying image, again



Again, what I'm trying to do is read an image from the disk and display
it, using gtkmm-1.2.10. I almost got that to work, the window is
displayed, has the same size as the image from file, but the image is
displayed truncated (the upper 1/3 or so is not visible). Someone please
help, I'm pulling hair here.

After countless hours of digging into the docs and into the header files,
I've come up with the sample code below. I'm trying to keep it very simple
for now, so there are no signals, etc., just read the image and display
it.

// winminimal.C
//
// g++ -o win winminimal.C `gtkmm-config --cflags --libs` `imlib-config
--cflags-gdk --libs-gdk`
//
// run as:
// win imagefile
//

#include <gtk--/window.h>
#include <gtk--/main.h>
#include <gtk--/drawingarea.h>
#include <gtk--/style.h>
#include <gdk_imlib.h>
#include <gdk/gdk.h>

using namespace std;

int main(int argc, char * argv[])
{
    Gtk::Main foobar(argc, argv);
    Gtk::Window w;
    Gtk::DrawingArea da;

    // The image
    GdkImlibImage * I;
    guint width, height;

    // Initializations
    gdk_imlib_init();
    gdk_rgb_init();

    // Read the image
    I=gdk_imlib_load_image(argv[1]);
    width=I->rgb_width;
    height=I->rgb_height;

    // set sizes and add the drawing area to the window
    w.set_usize(width, height);
    da.set_usize(width, height);
    w.add(da);

    // realize
    da.show();
    w.show();

    // Draw the image buffer into the window
    gdk_draw_rgb_image (da.get_window().gdkobj(),
			da.get_style()->get_fg_gc(GTK_STATE_NORMAL),
			0, 0, width, height,
			GDK_RGB_DITHER_MAX, I->rgb_data, width * 3);

    foobar.run();

    return 0;
}





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