X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/906c935a80b10d53cecf57f71ab5f3f4f1d529ec..66815259f590d8a88cab69e0a813bc6e8c6029cc:/samples/image/canvas.cpp diff --git a/samples/image/canvas.cpp b/samples/image/canvas.cpp index 3bff81316f..cdba69aa43 100644 --- a/samples/image/canvas.cpp +++ b/samples/image/canvas.cpp @@ -35,6 +35,7 @@ #include "smile.xbm" #include "smile.xpm" +#include "cursor_png.c" #include "canvas.h" @@ -243,7 +244,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, #if wxUSE_LIBTIFF image.Destroy(); - if ( !image.LoadFile( dir + wxT("horse.tif"), wxBITMAP_TYPE_TIF ) ) + if ( !image.LoadFile( dir + wxT("horse.tif"), wxBITMAP_TYPE_TIFF ) ) { wxLogError(wxT("Can't load TIFF image")); } @@ -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()