我需要能够将透明的PNG图像作为图层添加到ImgView32(来自graphics32库)。 有谁知道如何实现这一目标?
基本上,我可以将任何图像作为图层添加到我的Image32中,但所有图像(即使它们本质上是透明的)都具有白色背景。 我需要解决这个问题。 有人有任何想法吗?
这就是我将图像添加为图层的方式:
var
B: TBitmapLayer;
P: TPoint;
W, H: Single;
const
MasterAlpha: SmallInt = 100;
begin
with OpenPictureDialog do
if Execute then
begin
B := TBitmapLayer.Create(ImgView321.Layers);
with B do
try
Bitmap.LoadFromFile(FileName);
Bitmap.DrawMode := dmTransparent;
with ImgView321.GetViewportRect do
P := ImgView321.ControlToBitmap(GR32.Point((Right + Left) div 2, (Top + Bottom) div 2));
W := Bitmap.Width * 0.5;
H := Bitmap.Height * 0.5;
with ImgView321.Bitmap do
Location := GR32.FloatRect(P.X - W, P.Y - H, P.X + W, P.Y + H);
Scaled := True;
B.Bitmap.CombineMode := cmBlend;
B.Bitmap.DrawMode := dmTransparent;
OnMouseDown := LayerMouseDown;
OnKeyUp :=LayerKeyUp;
except
Free;
raise;
end;
Selection := B;
end;
end;
所以我设置 Bitmap.DrawMode:= dmTransparent; 似乎并不重要。即使我添加PNGImage使用,没有任何变化,除了我现在可以选择png图像添加到我的图像
所以请告诉我我做错了什么,我该怎么做才能解决这个问题。
谢谢
修改
我知道将PNG加载到Bitmap32中,如此链接http://graphics32.org/wiki/FAQ/ImageFormatRelated所述,但显然我“无法将TBitmap32分配给TBitmapLayer”,因此将透明PNG加载到Bitmap32之后就好了(理论上)如何将它分配给我的图层?