Page 1 of 1

Converting Magick::Images to wxImages and displaying

Posted: 2012-06-30T14:10:37-07:00
by gone_postal0123
Hello Everyone,

I was hoping someone could give me an idea on the best method for converting a Magick::Image to a wxImage to be then drawn on screen using a paintDC. I have had a long scan online but haven't yet found a simple method that works yet, I've concluded its something I'm definitely missing in my code. :?

At the moment I have a very simple wxControl that I hope to have display the converted image. Here is the constructor:

Code: Select all

Canvas::Canvas(wxWindow* parent) :
  
  wxControl(parent, wxID_ANY, wxDefaultPosition, wxSize(parent->GetSize().GetWidth(),parent->GetSize().GetHeight()))
{
  
  m_imageBufferSize = GetSize().GetHeight() * GetSize().GetWidth() * 4;
  
  m_imageBuffer = new unsigned char[m_imageBufferSize];
  
  m_magImage = new Magick::Image("myImage.jpg");
  m_magImage->depth( 8 ); 
    
  m_magImage->writePixels( Magick::RGBQuantum, m_imageBuffer );
 
  GetEventHandler()->Connect(wxEVT_PAINT, wxPaintEventHandler (Canvas::on_paint),0,this);
}
Assuming the writePixels has written the pixel data to m_imageBuffer I then use the buffer to create a wxImage which in turn is then converted to a wxBitmap and used in the paintDC.

Code: Select all

void Canvas::on_paint(wxPaintEvent& event)
{
    wxImage tempImage(GetSize().GetWidth(), GetSize().GetHeight(), m_imageBuffer, true);
  
    wxBitmap tempBmp(tempImage);

    wxBufferedPaintDC dc(this, tempBmp);
}

If anyone can help with this I'd really appreciate it and if I've left any details out just let me know.

Many Thanks!

-SL