问题描述
我遇到了一个陷阱,只是我,或者你不能将一个资源的图像分配给TSpeedButton的字形,而没有如下所示的可怕的黑色轮廓?
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?
我已经为TImage组件分配了完全相同的方式,我得到了所需的结果。
I've assigned it exactly the same way for the TImage component and I'm getting the result needed.
我一直在搜索虽然没有人似乎有这个奇怪和烦人的问题。
I've been searching for quite a while but no one seems to have this bizarre and annoying problem.
下面是我的源代码:
procedure TForm3.Button1Click(Sender: TObject);
var r : tresourcestream; png : tpngimage;
begin
r := tresourcestream.CreateFromID(hinstance,34,'cardimage');
png := tpngimage.Create;
png.LoadFromStream(r);
png.AssignTo(image1.Picture.bitmap);
png.AssignTo(speedbutton1.glyph);
png.Free;
r.Free;
end;
34是与图片中显示的图像相关的cardimage类型的图像,如果您还没有猜到。
34 is the image of type 'cardimage' that relates to the image being shown in the picture if you haven't guessed already.
推荐答案
这个问题显然是左边图片中的alpha 频道被忽略。现在, TSpeedButton.Glyph
属性是一个 TBitmap
,所以保存PNG alpha通道可能是有问题的。例如,
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);
生成
一个部分解决方案是预先混合PNG图像:
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);
这篇关于是否可以删除TSpeedButton字形周围的可怕轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!