From 338cf327b0eed08784ca244652ba198a4e021751 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Mar 2014 18:46:10 +0000 Subject: [PATCH] Don't change bitmap depth in wxMSW when copying it. Sometimes, creating a DDB may fail to create the bitmap of the requested depth and so a copy of wxBitmap could have a different depth than the original wxBitmap. Avoid this problem by falling back on using DIB if DDB with the right depth couldn't be created. Closes #11640. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76196 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/bitmap.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index d75fb0c66e..5d28a921da 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -243,6 +243,28 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) { wxDIB dib((HBITMAP)(data.m_hBitmap)); CopyFromDIB(dib); + BITMAP bm; + if ( ::GetObject(m_hBitmap, sizeof(bm), &bm) != sizeof(bm) ) + { + wxLogLastError(wxT("GetObject(hBitmap@wxBitmapRefData)")); + } + else if ( m_depth != bm.bmBitsPixel ) + { + // We got DDB with a different colour depth then we wanted, so we + // can't use it and need to continue using the DIB instead. + wxDIB dibDst(m_width, m_height, m_depth); + if ( dibDst.IsOk() ) + { + memcpy(dibDst.GetData(), dib.GetData(), + wxDIB::GetLineSize(m_width, m_depth)*m_height); + AssignDIB(dibDst); + } + else + { + // Nothing else left to do... + m_depth = bm.bmBitsPixel; + } + } } #endif // wxUSE_WXDIB }