Converting Magick::Images to wxImages and displaying

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
gone_postal0123
Posts: 1
Joined: 2012-06-30T13:22:52-07:00
Authentication code: 13

Converting Magick::Images to wxImages and displaying

Post 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
Post Reply