I need to be able to add transparent PNG images as layers to a ImgView32 (from graphics32 library). Does anybody know how can this be achieved?
Basically, I can add any image as a layer to my Image32, but all images (even if they are transparent by nature) have a white background. I need to workaround this problem. Does anybody have any idea?
This is how I add my image as a layer:
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;
So it does not seem to matter that I set Bitmap.DrawMode := dmTransparent; it does nothing. Even if I added PNGImage to uses, nothing changes except I now can pick png images to add to my image
So please tell me what I am doing wrong and what should I do to solve this.
Thank you
EDIT
I am aware of Loading PNG into Bitmap32, as described in this link http://graphics32.org/wiki/FAQ/ImageFormatRelated but apparently I "cannot assign a TBitmap32 to a TBitmapLayer" so after loading the transparent PNG into a Bitmap32 just fine (in theory) how do I assign it to my layer?