Using wxMemoryDC is very fast, but no antialiasing.
With scale>=0.4, antialiasing is not helpful anyway, but you can decide.
No restriction in scale except scale <= 0.
The trick was realizing that the selected bmpOut in the device context is actually the target of the blitter.
Code: Select all
#include <wx/dcgraph.h>
wxBitmap ScaleBitmap(wxBitmap &bmpIn, double scale, bool antialiasing)
{
if(scale <= 0.0)
return wxNullBitmap;
wxSize sizeIn = bmpIn.GetSize();
wxSize sizeOut((int)sizeIn.GetX()*scale, (int)sizeIn.GetY()*scale);
wxBitmap bmpOut;
bmpOut.Create(sizeOut); // the final size
wxMemoryDC inDC(bmpIn);
if(antialiasing && scale<0.4)
{
wxGCDC outDC(bmpOut);
outDC.StretchBlit(wxPoint(0,0), sizeOut, &inDC, wxPoint(0,0), sizeIn);
}
else
{
wxMemoryDC outDC(bmpOut);
outDC.StretchBlit(wxPoint(0,0), sizeOut, &inDC, wxPoint(0,0), sizeIn);
outDC.SelectObject(wxNullBitmap);
}
inDC.SelectObject(wxNullBitmap);
return bmpOut;
}