diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index d490d88922..ae48064330 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -232,24 +232,40 @@ wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) if ( data.m_hBitmap ) { wxDIB dib((HBITMAP)(data.m_hBitmap)); - // DDB obtained from CopyFromDIB() can have different - // colour depth than source DIB so we need to check it. - CopyFromDIB(dib); - if ( m_depth != dib.GetDepth() ) + + // Cloning a DIB should create a DIB, while cloning a DDB should create + // a DDB, so check what do we have. + if ( data.m_isDIB ) { - // We got DDB with a different colour depth than we wanted, so we - // can't use it and need to continue using the DIB instead. - wxDIB dibDst(m_width, m_height, dib.GetDepth()); - if ( dibDst.IsOk() ) + const int w = dib.GetWidth(); + const int h = dib.GetHeight(); + const int d = dib.GetDepth(); + + wxDIB dibDst(w, h, d); + memcpy(dibDst.GetData(), dib.GetData(), wxDIB::GetLineSize(w, d)*h); + InitFromDIB(dibDst); + } + else + { + // DDB obtained from CopyFromDIB() can have different + // colour depth than source DIB so we need to check it. + CopyFromDIB(dib); + if ( m_depth != dib.GetDepth() ) { - m_depth = dib.GetDepth(); - memcpy(dibDst.GetData(), dib.GetData(), - wxDIB::GetLineSize(m_width, m_depth)*m_height); - AssignDIB(dibDst); - } - else - { - // Nothing else left to do... + // We got DDB with a different colour depth than we wanted, so we + // can't use it and need to continue using the DIB instead. + wxDIB dibDst(m_width, m_height, dib.GetDepth()); + if ( dibDst.IsOk() ) + { + m_depth = dib.GetDepth(); + memcpy(dibDst.GetData(), dib.GetData(), + wxDIB::GetLineSize(m_width, m_depth)*m_height); + AssignDIB(dibDst); + } + else + { + // Nothing else left to do... + } } } }