Add wxBitmap::NewFromPNGData() for creating bitmaps from PNG data.

This simple function can be used to create a wxBitmap from the raw image data
in PNG format. It is just a thin wrapper around wxImage load functions under
almost all platforms but has two advantages:

1. It can be implemented natively for some platforms (currently only OS X).
2. It can be used in a single expression as it doesn't require creating a
   temporary wxMemoryInputStream and this will be required by wxBITMAP_PNG()
   macro that will be added soon.

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

View File

@@ -23,6 +23,12 @@
#include "wx/image.h"
#endif // WX_PRECOMP
#if wxUSE_IMAGE && wxUSE_LIBPNG && wxUSE_STREAMS
#define wxHAS_PNG_LOAD
#include "wx/mstream.h"
#endif
// ----------------------------------------------------------------------------
// wxVariant support
// ----------------------------------------------------------------------------
@@ -37,6 +43,31 @@ IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxIcon,WXDLLEXPORT)
//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<wxIcon>)
#endif
// ----------------------------------------------------------------------------
// wxBitmapHelpers
// ----------------------------------------------------------------------------
// wxOSX has a native version and doesn't use this one.
#ifndef __WXOSX__
/* static */
wxBitmap wxBitmapHelpers::NewFromPNGData(const void* data, size_t size)
{
wxBitmap bitmap;
#ifdef wxHAS_PNG_LOAD
wxMemoryInputStream is(data, size);
wxImage image(is, wxBITMAP_TYPE_PNG);
if ( image.IsOk() )
bitmap = wxBitmap(image);
#endif // wxHAS_PNG_LOAD
return bitmap;
}
#endif // !__WXOSX__
// ----------------------------------------------------------------------------
// wxBitmapBase
// ----------------------------------------------------------------------------