[gtkmm] Please help with displaying images



Hi,
 
I am having a lot of trouble trying to figure out quite how to create a widget for displaying an image. Basically I have got a character array, representing an 8 bit image and I want to draw it straight to the screen with minimal copying. I think I need to get a Drawable object for my widget, but I can't figure out how to do that, and so I get compiler errors. I would really appreciate it if someone could:
 
a: Tell me how to fix my code (I hope it's fairly self-explanatory where the error is, right at the bottom of the source file)
b: Direct me to an example which specifically uses the draw_gray_image or draw_indexed_image functions to achieve the same effect.
 
Also, I discovered the pixmap class. Can I use that achieve the same effect using this class? (I want it to take the buffer as it's own, rather than make a copy, and I also want to draw on the image). I would still be curious to know how to fix the code though.
 
Thanks for any help.
 
Ben Stephens
 

-----------------------------------------------------------------------------------------------------------------
 
Header file:
 
class DisplayWidget : public Gtk::DrawingArea
{
 public:
  SlamGUIDisplay();
  ~SlamGUIDisplay();
 
 protected:
  // The redraw event
  virtual bool on_expose_event(GdkEventExpose *event);
  
  virtual void on_realize();
  
  // Area to store image data
  char m_Image[500000];
  
  // Graphics context
  Glib::RefPtr<Gdk::GC> gc;
};
 
------------------------------------------
Source file:
 

#include "slamguidisplay.h"
 
SlamGUIDisplay::SlamGUIDisplay()
{
 int n;
 
 // Create an image (temporary code)
 for (n = 0; n < 320 * 240; n++)
  m_Image[n] = n % 320;
}
 
SlamGUIDisplay::~SlamGUIDisplay()
{
 
}
 
// Called when the window is created. Only now can you get a valid GC for the window
// This is called only once on startup
void SlamGUIDisplay::on_realize()
{
 // Must call base version
 Gtk::DrawingArea::on_realize();
 
 // Get a GC (Graphics Context)
 Glib::RefPtr<Gdk::Window> window = get_window();
 gc = Gdk::GC::create(window);
}
 
// Expose or paint event - called if part or all of the window needs updating
bool SlamGUIDisplay::on_expose_event(GdkEventExpose *event)
{
 // ** THIS WILL CAUSE AN ERROR (obviously) BECAUSE I CAN'T GET A DRAWABLE OBJECT **
 Gdk::Drawable::draw_gray_image(gc, 0, 0, 320, 240, GDK_RGB_DITHER_NORMAL, (guchar*)m_Image, 320);
}


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