Fix conversion of bitmaps with alpha to icons/cursors in wxMSW.
CreateIconIndirect() applies pre-multiplication to the bitmap itself (as can be seen by experimenting with this or reading WINE sources for it) and so we must pass it a bitmap with data in non-pre-multiplied format to avoid doing it twice. This is similar to the change to wxImageList in the previous commit, see #9050. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65961 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1633,6 +1633,21 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp,
|
|||||||
|
|
||||||
if ( bmp.HasAlpha() )
|
if ( bmp.HasAlpha() )
|
||||||
{
|
{
|
||||||
|
HBITMAP hbmp;
|
||||||
|
|
||||||
|
#if wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
|
// CreateIconIndirect() requires non-pre-multiplied pixel data on input
|
||||||
|
// as it does pre-multiplication internally itself so we need to create
|
||||||
|
// a special DIB in such format to pass to it. This is inefficient but
|
||||||
|
// better than creating an icon with wrong colours.
|
||||||
|
AutoHBITMAP hbmpRelease;
|
||||||
|
hbmp = wxDIB(bmp.ConvertToImage(),
|
||||||
|
wxDIB::PixelFormat_NotPreMultiplied).Detach();
|
||||||
|
hbmpRelease.Init(hbmp);
|
||||||
|
#else // !(wxUSE_WXDIB && wxUSE_IMAGE)
|
||||||
|
hbmp = GetHbitmapOf(bmp);
|
||||||
|
#endif // wxUSE_WXDIB && wxUSE_IMAGE
|
||||||
|
|
||||||
// Create an empty mask bitmap.
|
// Create an empty mask bitmap.
|
||||||
// it doesn't seem to work if we mess with the mask at all.
|
// it doesn't seem to work if we mess with the mask at all.
|
||||||
HBITMAP hMonoBitmap = CreateBitmap(bmp.GetWidth(),bmp.GetHeight(),1,1,NULL);
|
HBITMAP hMonoBitmap = CreateBitmap(bmp.GetWidth(),bmp.GetHeight(),1,1,NULL);
|
||||||
@@ -1647,7 +1662,7 @@ HICON wxBitmapToIconOrCursor(const wxBitmap& bmp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
iconInfo.hbmMask = hMonoBitmap;
|
iconInfo.hbmMask = hMonoBitmap;
|
||||||
iconInfo.hbmColor = GetHbitmapOf(bmp);
|
iconInfo.hbmColor = hbmp;
|
||||||
|
|
||||||
HICON hicon = ::CreateIconIndirect(&iconInfo);
|
HICON hicon = ::CreateIconIndirect(&iconInfo);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user