title: Delphi TSpeedButton Glyph Transparency
body: <p>I'm currently working with a component called TdsTaskBar, which intends to work like the TaskBar in windows, which means all opened windows (but now inside my application) are listed as buttons on the bottom of my application-window. This buttons are TSpeedButtons.
  Now I've changed the icons of my own windows, this icons get always displayed via the glyph of the SpeedButtons. The problem is, that the transparency isn't working.</p>
  
  <p>I'm aware of the Transparency Color defined by the lower left corner pixel, but that's not my problem. The problem is, that transparent areas of the Glyphs show "random" image artifacts instead of the button-background, when changing the active window and then hovering over the buttons. This changes the background to the icon of the now active window, but with some distortion.</p>
  
  <p><a href="https://i.stack.imgur.com/N2o45.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N2o45.png" alt="First window opened"></a>
  <a href="https://i.stack.imgur.com/bp9Qv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bp9Qv.png" alt="Second window opened, hovered over the button"></a></p>
  
  <p>I have NO clue how this artifacts get there, but I'm sure that it doesn't come from the TdsTaskBar- / TdsTaskButton-Component, because I examined all the paint-relevant procedures.</p>
  
  <p>Does someone have an idea how to solve this problem? I already thought about drawing the background myself, but therefore I'd need to know the actual button color(s) behind this Glyph, and that's another thing where I'm not sure about how to figure it out. </p>
  
  <hr>
  
  <p>Here the code snippet for assigning the glyph, the drawing is handled by standard Vcl SpeedButton Code:</p>
  
  <pre><code>procedure TTaskBarButton.AssignGlyphIcon;
  var
    GlyphIcon: TIcon;
    b: TBitmap;
  begin
    if TForm(owner).Icon.Empty then
      GlyphIcon := Application.Icon
    else
      GlyphIcon := TForm(owner).Icon;
  
    b := TBitmap.create;
    try
      b.Width := GlyphIcon.Width;
      b.Height := GlyphIcon.Height;
      b.Canvas.Brush.Color := b.TransparentColor;    // This two lines were added by me
      b.Canvas.FillRect(b.ClipRect);         // so that the background of my "helper" bitmap is transparent, too
      b.Canvas.Draw(0,0, GlyphIcon);
      Glyph.Width := 16;
      Glyph.Height := 16;
      Glyph.Canvas.StretchDraw(Rect(0, 0, 16, 16), b);
    finally
      b.free;
    end;
  end;
  </code></pre>