Is it possible to remove hideous outline around a TSpeedButton glyph?

前端 未结 1 915
猫巷女王i
猫巷女王i 2020-12-30 00:36

I\'ve run into a bit of a snag, is it just me or can you not assign an image from a resource to TSpeedButton\'s glyph without a hideous black outline as shown below?

相关标签:
1条回答
  • 2020-12-30 00:52

    The issue is clearly that the alpha channel is ignored in the left picture. Now, the TSpeedButton.Glyph property is a TBitmap, so it might be problematic to preserve the PNG alpha channel. For example,

    var
      png: TPNGImage;
    begin
      png := TPngImage.Create;
      png.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\alpha.png');
      SpeedButton1.Glyph.Assign(png); // or png.AssignTo(SpeedButton1.Glyph);
    

    produces

    One partial solution is to pre-blend the PNG image:

    var
      png: TPNGImage;
      bm: TBitmap;
    begin
      png := TPngImage.Create;
      png.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\alpha.png');
      bm := TBitmap.Create;
      bm.SetSize(png.Width, png.Height);
      bm.Canvas.Brush.Color := Self.Color;
      bm.Canvas.FillRect(Rect(0, 0, bm.Width, bm.Height));
      bm.Canvas.Draw(0, 0, png);
      SpeedButton1.Glyph.Assign(bm);
    

    0 讨论(0)
提交回复
热议问题