unsigned char* pixels = dib.GetData();
for (int idx=0; idx<w*h*4; idx+=4)
{
- if (pixels[idx+3] != 0)
+ if (pixels[idx+3] != 0)
{
// If there is an alpha byte that is non-zero then set the
// alpha flag and bail out of the loop.
#endif
if ( !refData->m_hasAlpha )
{
- // the mask returned by GetIconInfo() is inversed compared to the usual
+ // the mask returned by GetIconInfo() is inverted compared to the usual
// wxWin convention
refData->SetMask(wxInvertMask(iconInfo.hbmMask, w, h));
}
-
+
// delete the old one now as we don't need it any more
::DeleteObject(iconInfo.hbmMask);
{
// we assume that it is in XBM format which is not quite the same as
// the format CreateBitmap() wants because the order of bytes in the
- // line is inversed!
+ // line is reversed!
const size_t bytesPerLine = (width + 7) / 8;
const size_t padding = bytesPerLine % 2;
const size_t len = height * ( padding + bytesPerLine );
SetMask(new wxMask((WXHBITMAP)hbitmap));
}
- delete data;
+ delete[] data;
}
return true;
#ifndef __WXMICROWIN__
// handle alpha channel, if any
if (HasAlpha())
- ret.UseAlpha();
+ ret.UseAlpha();
// copy bitmap data
MemoryHDC dcSrc,
HBITMAP hDIB;
if ( !GetBitmapData()->m_isDIB )
{
- wxCHECK_MSG( !GetBitmapData()->m_dib, FALSE,
+ wxCHECK_MSG( !GetBitmapData()->m_dib, NULL,
_T("GetRawData() may be called only once") );
wxDIB *dib = new wxDIB(*this);
// this value must be 1, 4, 8 or 24 so PixelDepth can only be
lpDIBheader->bmiHeader.biBitCount = (WORD)(bitsPerPixel);
lpDIBheader->bmiHeader.biCompression = BI_RGB;
- lpDIBheader->bmiHeader.biSizeImage = xSize * abs(ySize) * bitsPerPixel >> 3;
+ lpDIBheader->bmiHeader.biSizeImage = (xSize * abs(ySize) * bitsPerPixel) >> 3;
lpDIBheader->bmiHeader.biClrUsed = 256;
return 0;
}
- wxMask *mask = bmp.GetMask();
+ wxMask* mask;
+ wxBitmap newbmp;
+ if ( bmp.HasAlpha() )
+ {
+ // Convert alpha to a mask. NOTE: It would be better to actually put
+ // the alpha into the icon instead of making a mask, but I don't have
+ // time to figure that out today.
+ wxImage img = bmp.ConvertToImage();
+ img.ConvertAlphaToMask();
+ newbmp = wxBitmap(img);
+ mask = newbmp.GetMask();
+ }
+ else
+ {
+ mask = bmp.GetMask();
+ }
+
if ( !mask )
{
// we must have a mask for an icon, so even if it's probably incorrect,
HICON hicon = ::CreateIconIndirect(&iconInfo);
- if ( !bmp.GetMask() )
+ if ( !bmp.GetMask() && !bmp.HasAlpha() )
{
// we created the mask, now delete it
delete mask;