具有透明度的位图
使用代码
procedure TForm2.Button1Click(Sender: TObject);
var
oMeta: TMetaFile;
oBmp: TBitmap;
begin
Image1.Transparent := True;
Image1.Picture.LoadFromFile('D:\data\WMF.wmf');
oBmp := TBitmap.Create;
try
oMeta := TMetaFile(Image1.Picture.Graphic);
oBmp.SetSize(oMeta.Width, oMeta.Height);
oBmp.Canvas.Draw(0, 0, oMeta);
oBmp.SaveToFile('D:\data\WMF.bmp');
finally
oBmp.Free;
end;
end;
我显示 wmf 图像并创建 bmp 文件。创建的 bmp 图像我用代码显示
procedure TForm2.Button2Click(Sender: TObject);
begin
Image1.Transparent := True;
Image1.Picture.LoadFromFile('D:\data\WMF.bmp');
end;
,但图像显示没有透明度。为什么?如何以透明方式显示此 bmp 图像?
TIA 和最诚挚的问候 布兰科
With code
procedure TForm2.Button1Click(Sender: TObject);
var
oMeta: TMetaFile;
oBmp: TBitmap;
begin
Image1.Transparent := True;
Image1.Picture.LoadFromFile('D:\data\WMF.wmf');
oBmp := TBitmap.Create;
try
oMeta := TMetaFile(Image1.Picture.Graphic);
oBmp.SetSize(oMeta.Width, oMeta.Height);
oBmp.Canvas.Draw(0, 0, oMeta);
oBmp.SaveToFile('D:\data\WMF.bmp');
finally
oBmp.Free;
end;
end;
I Show wmf image and create bmp file. Created bmp image I show with code
procedure TForm2.Button2Click(Sender: TObject);
begin
Image1.Transparent := True;
Image1.Picture.LoadFromFile('D:\data\WMF.bmp');
end;
but image is shown without transparency. Whay ? How can I show this bmp image with transparency ?
TIA and best regards
Branko
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您应该知道透明 BMP 非常罕见。因此,许多(大多数)位图查看器、编码器和解码器不支持透明位图。不过,还是有一些希望的。首先,许多位图都是 32 位的,尽管像素通常以 $00BBGGRR 格式存储。因此,每个“像素”的第一个字节未被使用,当然可以使用它作为不透明度值:$AABBGGRR。但这不仅仅是我个人的想法。大多数位图使用版本 3 位图标头,但是版本 4(和版本 5)实际上支持透明度数据。您只需指定红色、绿色、蓝色和 Alpha 遮罩(例如,分别为 $000000FF、$0000FF00、$00FF0000 和 $FF000000),然后就可以存储每个像素的红色、绿色、蓝色和 Alpha 强度。
尽管如此,正如我所说,大多数位图查看器、编码器和解码器不支持透明位图。我认为 VCL 编码器、解码器和查看器 (
TImage
) 不会。我会考虑使用 PNG 而不是 BMP。 PNG 位图图像格式以多种不同方式支持透明度。
First of all, you should know that transparent BMP's are very uncommon. Hence, many (most) bitmap viewers, encoders, and decoders do not support transparent bitmaps. However, there is some hope. First of all, many bitmaps are 32-bit, even though the pixels most often are stored in the format $00BBGGRR. The first byte of each "pixel" is hence unused, and one could of course use this as the opacity value: $AABBGGRR. But this is not only my personal ideas. Most bitmaps use the version 3 bitmap header, but version 4 (and version 5) actually supports transparency data. You simply specify the red, green, blue, and alpha masks (e.g. $000000FF, $0000FF00, $00FF0000, and $FF000000, respectively) and then you can store red, green, blue, and alpha intensities per pixel.
Still, as I said, most bitmap viewers, encoders, and decoders doesn't support transparent bitmaps. I think that the VCL encoders, decoders, and viewer (
TImage
) don't.I would consider using PNG instead of BMP. The PNG bitmap image format supports transparency in a lot of different ways.
位图不支持透明度,除非它是 32 位 AFAIR。但我不确定是否可以在没有第三方组件的情况下在 Delphi 中完成。您可以尝试使用 png 代替位图。 Delphi 有 TPNGImage 来实现这一点。
Bitmap doesn't support transparency unless it's 32 bit AFAIR. But I am not sure if it's possible to do in Delphi without 3rd party components. You can try to use png instead of bitmap. Delphi has TPNGImage for that.