Hi,
it looks like I have problems to full understand the way, alpha transparency is handled by ImageEN.
Let's start with a 32bit standard TBitmap, that has set semi transparency:
bmp := TBitmap.Create;
try
bmp.SetSize(300, 300);
bmp.PixelFormat := pf32bit;
bmp.AlphaFormat := afDefined;
bmp.Canvas.Brush.Color := clRed;
bmp.Canvas.FillRect(Rect(0,0, bmp.Width, bmp.Height));
// now set some parts of the image semi-transparent
for y := 0 to bmp.Height - 1 do
begin
P := bmp.ScanLine[y];
for x := 0 to bmp.Width - 1 do
begin
p^.rgbReserved := (128 + y) mod 255;
inc(p);
end;
end;
...
Now my task is: display that bitmap with ImageEnView component (LegacyBitmap is set true)
1) I tried simple assignment: ImageEnView1.Assign(bmp);
This results in the bitmap but without any transparency
2) Next I tried to EnableAlphaChannel:
no change, no transparency
3) Try to copy the alpha values from bitmap to AlphaChannel by hand:
for y := 0 to ImageEnView1.Bitmap.Height - 1 do
begin
P := bmp.ScanLine[y];
pa := ImageEnView1.AlphaChannel.ScanLine[y];
for x := 0 to ImageEnView1.Bitmap.Width - 1 do
begin
pa^:= p^.rgbReserved;
inc(p);
inc(pa);
end;
end;
Result: still no transparency ?!
4) As a last trial, I set AlphaChannel.Full on false:
ImageEnView1.Assign(bmp);
ImageEnView1.EnableAlphaChannel := true;
ImageEnView1.AlphaChannel.Full := false;
for y := 0 to ImageEnView1.Bitmap.Height - 1 do
begin
P := bmp.ScanLine[y];
pa := ImageEnView1.AlphaChannel.ScanLine[y];
for x := 0 to ImageEnView1.Bitmap.Width - 1 do
begin
pa^:= p^.rgbReserved;
inc(p);
inc(pa);
end;
end;
Yippie, now the bitmap is shown with alpha transparency!
But now my question is: this looks a little bit complicated and needed a lot of trials to find out. So is there a simpler way to display the bitmap, especially when LegacyBitmap := true?
And why for active LegacyBitmaps, alpha channel is not automatically filled on assigning such a bitmap?
Please add such workflows to documentation!
best regards,
Ulrich