Add wxBITMAP_PNG() macro similar to wxBITMAP() but for PNG images.

Just as wxBITMAP() provides a portable way of loading bitmaps from either
Windows BMP resources or embedded XPM data depending on the platform,
wxBITMAP_PNG() hides the difference between loading bitmaps from PNG resources
under Windows and embedded PNG data elsewhere.

Also add wxBITMAP_PNG_FROM_DATA() macro which always loads PNG data from
memory: it's needed anyhow as part of wxBITMAP_PNG() implementation and some
people may prefer to always use it under all platforms.

Finally modify the image sample to demonstrate loading PNG images from both
resources and memory. This involved creation of a new Windows .rc file for it
and copying its data files to Resources bundle directory under OS X.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-13 17:15:25 +00:00
parent 20e6714a67
commit c3f641cb5e
20 changed files with 328 additions and 36 deletions

View File

@@ -35,6 +35,7 @@
#include "smile.xbm"
#include "smile.xpm"
#include "cursor_png.c"
#include "canvas.h"
@@ -376,6 +377,19 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
free(data);
}
// This macro loads PNG from either resources on the platforms that support
// this (Windows and OS X) or from in-memory data (coming from cursor_png.c
// included above in our case).
my_png_from_res = wxBITMAP_PNG(cursor);
// This one always loads PNG from memory but exists for consistency with
// the above one and also because it frees you from the need to specify the
// length explicitly, without it you'd have to do it and also spell the
// array name in full, like this:
//
// my_png_from_mem = wxBitmap::NewFromPNGData(cursor_png, WXSIZEOF(cursor_png));
my_png_from_mem = wxBITMAP_PNG_FROM_DATA(cursor);
}
MyCanvas::~MyCanvas()
@@ -635,6 +649,13 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
dc.DrawBitmap( my_horse_ani[i], 230 + i * 2 * my_horse_ani[i].GetWidth() , 2420, true );
}
}
dc.DrawText("PNG from resources", 30, 2460);
if ( my_png_from_res.IsOk() )
dc.DrawBitmap(my_png_from_res, 30, 2480, true);
dc.DrawText("PNG from memory", 230, 2460);
if ( my_png_from_mem.IsOk() )
dc.DrawBitmap(my_png_from_mem, 230, 2480, true);
}
void MyCanvas::CreateAntiAliasedBitmap()