Re: ImageList_Draw and icons with alpha channel



You were correct. I need to use
CImageList::Add(m_h32bppXORMask,m_h32bppANDMask);

As In:
// add the 32bpp Alpha Icon Bitmap Masks to a new imagelist and draw it to
the dialog
WTL::CImageList iml;
iml.Create(90, 32, ILC_COLOR32 | ILC_MASK, 2, 0); // Explorer icon with
highlighted "Hello" text next to the icon
iml.Add(m_h32bppXORMask,m_h32bppANDMask); // This is the icon that I
created with my previous post
DeleteObject(m_h32bppXORMask);
DeleteObject(m_h32bppANDMask);
iml.SetBkColor(CLR_NONE);
SetBkColor(ps.hdc, GetSysColor(COLOR_3DFACE));
iml.Draw(ps.hdc, 0, 10, 90, ILD_NORMAL);
iml.Destroy();

The image displays correctly with XPSP2 and Windows 2003SP1

"Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx> wrote in message
news:OlfocEm2FHA.2816@xxxxxxxxxxxxxxxxxxxxxxx
> There are several CImageList Add methods.
>
> The one that I think will work best for you is
> Add(HICON hIcon).
>
> Here is what I did:
>
> 1) Load the icons as you describe in your code
> 2) Create a Memory DC and DIBSECTION bitmap
> for each bitdepth. You will need a Palette for 8bpp or less bitmaps.
> 3) Select the Dib into the device context
> 4) Use DrawIcon to draw the icon to the memory device
> 5) Use DrawText as in your code to draw the text next to the icon.
> 6) After you use SelectObject and DeleteDC, you now have a
> bitmap with the icon and captioned text next to it.
> 7) You now need to create the XOR and AND masks from this DIB
> For the XOR mask use CreateCompatibleBitmap (i.e., create another
> DIBSECTION)
> For the AND mask use CreateBitmap
> Create memory DC's for each and select the bitmaps into the DC's
>
> Use SetDIBColorTable for 8bpp or less bitmaps before creating the masks
> to make sure the destination XOR bitmap has a color table.
>
> Here is my code for the masks:
>
> // Create AND and XOR masks
> for ( DWORD x = 0; x < dwWidth; x++ )
> {
> for ( DWORD y = 0; y < dwHeight; y++ )
> {
> // clrTransparent is a COLORREF for the transparent color
> // You could sample using GetPixel
> if ( ::GetPixel( hSrcImageDC, x ,y ) == clrTransparent ) // Src Bitmap
> from above
> {
> ::SetPixel( hAndMaskDC, x, y, RGB(255, 255, 255) );
> ::SetPixelV( hXorMaskDC, x, y, RGB(0,0,0) );
> }
> else
> {
> ::SetPixel( hAndMaskDC, x, y, RGB(0,0,0) );
> ::SetPixel( hXorMaskDC, x, y, ::GetPixel( hSrcImageDC, x ,y ) );
> }
> }
> }
> ::GdiFlush();
>
> 8) Now that you have the masks you need to create an Icon
> using CreateIconIndirect
> 9) Add the icons to your image list with Add(HICON hIcon).
>
> Converting the DIB format for each bitdepth is easy. I use BitBlt
> to do all of the work.
>
> Because your sample Icon has shadows, I found that using the 8bpp
> icon as the source gave the best results. You may need to fixup
> the icon first to eliminate the artifacts produced by the Mask creation.
>
>
> "Timo Kunze" <TKunze71216@xxxxxx> wrote in message
> news:%230nUofl2FHA.3420@xxxxxxxxxxxxxxxxxxxxxxx
>> You draw the icon to the dialog and then the text next to it. This works
>> for me, too. But I need an imagelist that contains the icon with the
>> text next to it, i. e. I need icon and text within the same bitmap. This
>> imagelist will be used with ImageList_BeginDrag and the other
>> drag'n'drop functions.
>> So I create a XOR mask and an AND mask as you suggested. I've ensured
>> that the rectangle, that contains the text in the XOR mask, is all black
>> in the AND mask, so it won't be transparent in the combined picture.
>>
>> If I create an imagelist with ILC_COLORDDB | ILC_MASK and add the image
>> (i. e. both masks) which contains icon AND text, the drag image indeed
>> contains icon and text, BUT:
>> - Pixels that have an alpha transparency in the source icon are not
>> transparent anymore.
>> - On Windows 2003 the alpha transparency seems to be correct, but the
>> text is wrong. The text's background isn't blue as it should (and as it
>> is on XP), but white. I've absolutely no idea why this happens.
>>
>> If I create an imagelist with ILC_COLOR32 | ILC_MASK and add the image
>> (i. e. both masks) which contains icon AND text, alpha transparency
>> seems to be correct, but the drag image contains the icon only.
>> Could this have something to do with the palette? Or do I have to create
>> the bitmap, that I'm adding, with CreateDIBSection()?
>>
>> Here're 3 screenshots of how the drag image looks if the imagelist was
>> created with ILC_COLORDDB | ILC_MASK:
>> 1) Windows XP SP2 - drag image is correct, except that alpha
>> transparency is lost.
>> www.timosoft-software.de/stuff/WinXP.png
>> 2) Windows 2003 SP1 - alpha transpareny is correct, but the text's
>> background is white instead of blue (the ImageList_BeginDrag function
>> makes the drag image semi-transparent, so the blue titlebar shines
>> through and makes the text background light-blue).
>> www.timosoft-software.de/stuff/Win2k3.png
>> 3) Windows 2003 SP1 - OLE drag'n'drop, which displays my drag image
>> using IDragSourceHelper and IDropTargetHelper, displays the text
>> background correctly, but alpha-transparency is lost (you can't see this
>> on the screenshot).
>> www.timosoft-software.de/stuff/Win2k3OLE.png
>>
>> The box to the right of the listview displays the drag image and its
>> mask as they are added to the imagelist.
>>
>> BTW, I think it's wrong how you're adding the mask to the imagelist. You
>> call ImageList_Add() once for each image (image = XOR mask + AND mask).
>> If you want to specify a custom AND mask, you can do this using the 3rd
>> parameter of ImageList_Add().
>>
>> Timo
>> --
>> www.TimoSoft-Software.de - the home of ExplorerTreeView
>> Stop software patents!
>
>


.



Relevant Pages

  • Re: ImageList_Draw and icons with alpha channel
    ... Use DrawText as in your code to draw the text next to the icon. ... bitmap with the icon and captioned text next to it. ... For the AND mask use CreateBitmap ... but the drag image contains the icon only. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: ImageList_Draw and icons with alpha channel
    ... an XOR mask and an AND mask. ... Your code adds one bitmap. ... Use GetIconInfo to obtain a DDB XOR mask and the AND mask. ... > The next thing I do is draw an icon into that DC using ImageList_Draw ...
    (microsoft.public.win32.programmer.gdi)
  • Re: LoadImage replaces Transparent Background with Black, how can I fix that?
    ... > an Image and a Mask bitmap, so I rather suspect thet the 'transparent ... Yep, an icon is made up of two Bitmaps, one monochrome mask which defines which pixels are visible and a second image ... If you want to save an icon as a Bitmap or load an icon from a Bitmap using any colour as the 'transparent' colour then have a look ...
    (microsoft.public.vb.general.discussion)
  • Re: Tweaking images in Face list
    ... One alternative, which you might want to consider, is to use late binding code to call the Picture and Mask properties if the user is running Outlook 2002 or later and just put up an unmasked button for Outlook 2000. ... We would like to have a customized icon on the button, ... bitmap that is masked properly when applied to a commandbarbutton it ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: ImageList_Draw and icons with alpha channel
    ... You draw the icon to the dialog and then the text next to it. ... So I create a XOR mask and an AND mask as you suggested. ... - On Windows 2003 the alpha transparency seems to be correct, ... but the drag image contains the icon only. ...
    (microsoft.public.win32.programmer.gdi)