Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to display an array as image in wxWidgets

📅 2013-Dec-18 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ wxbitmap, wximage, wxstaticbitmap, wxwidgets ⬩ 📚 Archive

There are many scenarios where you get an array of values that represents an image of certain width and height. For example, the array could contain integers or floats of any range. You might want to display this array in wxWidgets to visualize it as a two-dimensional image.

Here is one way I was able to do this in wxWidgets:

unsigned char* imgArray[width * height * 3];
// Fill in imgArray here ... 
wxImage img(width, height, imgArray, true);
wxBitmap bmp(img);
// Start with empty bitmap
wxStaticBitmap* sbmp = new wxStaticBitmap(this, wxID_STATIC, wxNullBitmap, wxDefaultPosition, wxSize(width, height));
// Update later with your bitmap
sbmp->SetBitmap(bmp);

Tried with: wxWidgets 3.0.0 and Visual Studio 2012


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email