I have a control derived from wxWindow with EVT_PAINT callback. I want to display an image according to the following requirements:
- It should support alpha channel on all platforms (at least on MSW, GTK+ and OSX wxWidgets builds);
- The image should be resized with nearest neighbor interpolation (again, on all platforms);
- The image will be changed frequently, so it should provide a fast access to raw pixel data.
Code: Select all
void Canvas::OnPaint(wxPaintEvent &event)
{
wxAutoBufferedPaintDC dc(this);
wxGraphicsContext *gc = wxGraphicsContext::Create(dc);
if (gc != nullptr && this->image.IsOk()) {
double w = this->image.GetWidth() * this->scale;
double h = this->image.GetHeight() * this->scale;
dc.Clear();
gc->DrawBitmap(this->image.Scale(w, h, wxIMAGE_QUALITY_NEAREST),
0, 0, w, h);
delete gc;
}
event.Skip();
}