[DUG] Assigned image to SpeedButton not transparent

Jolyon Direnko-Smith jsmith at deltics.co.nz
Fri Oct 30 17:22:15 NZDT 2015


Retrieving the bitmap from an image list in the way that you are should
preserve transparency, if the transparency is correctly set in the image
list itself.

However, assigning a bitmap to the Glyph property in this way invokes a
behaviour in the Speedbutton class which may be interfering with things.

If your bitmap is a simple, single image (rather than one of the composite
images that a speedbutton glyph can support) then you could try simply
getting the bitmap directly into the glyph:

   ImageList.GetBitmap( N, SpeedButton.Glyph) );

This causes the ImageList to draw the requested image directly onto the
canvas of the specified bitmap, bypassing the setter behaviour in the
speedbutton.  if this is what is mangling the transparency then this may
solve your problem.


hth

On 30 October 2015 at 15:51, Ross Levis <ross at stationplaylist.com> wrote:

> Using D7/themes, I have a TSpeedButton which is a toggle and I need to
> display 2 different glyphs in a TSpeedButton based on whether the button
> was clicked or right-clicked, as they do 2 slightly different things.
>
>
>
> So I need to assign a glyph to the button at run time, which works, but
> nothing I do makes the image transparent. There is always a white square
> with the icon in the middle. It only looks correct if I assign one of the
> images to the Glyph property at design time.
>
>
>
> I use a TImageList to store the 2 images, and assign them like this as
> required.
>
>
>
> BitMap := TBitMap.Create;
>
> ImageList.GetBitmap(n,BitMap);
>
> SpeedButton.Glyph := BitMap;
>
> BitMap.Free;
>
>
>
> where n is 0 or 1.
>
>
>
> I've tried setting Bitmap.Transparent to true and other combinations like
> TransparentMode and TransparentColor but nothing makes any difference.
>
>
>
> There is some sort of transparency happening since the images have quite a
> colorful background but this appears as white on the button.
>
>
>
> As a test I assigned the image from a filename Button.Glyph.LoadFromFile()
> and this works correctly and looks good, but I don't want to distribute BMP
> files separately.
>
>
>
> A possible alternative I haven’t tried is embedding the 2 images as a
> resource in the EXE file and using Button.Glyph.LoadFromResourceName (or
> ResourceID), but that seems a lot of work.  I thought I would try here to
> see if anyone knows how to resolve the current method.
>
>
>
> Cheers,
>
> Ross.
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at listserver.123.net.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
> Subject: unsubscribe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20151030/937f43b7/attachment.html 


More information about the Delphi mailing list