From 527c25b898fa8535d4012e6effb6b921ede7d600 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 4 Jan 2016 22:59:44 +0100 Subject: [PATCH] Store alpha channel in the output wxImage only if internal GDI+ bitmap contains it. When converting internal bitmap to wxImage in wxGDIPlusBitmapData::ConvertToImage set up output alpha channel buffer only if source bitmap contains alpha channel values. --- src/msw/graphics.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index cfb7ad1acc..6c528a4d2c 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -1112,7 +1112,12 @@ wxImage wxGDIPlusBitmapData::ConvertToImage() const const UINT h = m_bitmap->GetHeight(); wxImage img(w, h); - img.InitAlpha(); + // Set up wxImage buffer for alpha channel values + // only if bitmap contains alpha channel. + if ( IsAlphaPixelFormat(m_bitmap->GetPixelFormat()) ) + { + img.InitAlpha(); + } BitmapData bitmapData; Rect rect(0, 0, w, h); @@ -1129,7 +1134,8 @@ wxImage wxGDIPlusBitmapData::ConvertToImage() const *imgRGB++ = (c >> 16) & 0xFF; // R *imgRGB++ = (c >> 8) & 0xFF; // G *imgRGB++ = (c >> 0) & 0xFF; // B - *imgAlpha++ = (c >> 24) & 0xFF; + if ( imgAlpha ) + *imgAlpha++ = (c >> 24) & 0xFF; } pixels += bitmapData.Stride;