I want to draw a bitmap on a canvas with opacity, where the bitmap has a transparent color.
- I could create a bitmap with a transparent color and draw it
- canvas i can create a bitmap and draw it on canvas with opacity
but I could not combine it. if I combine it, opacity is ignored.
here is the code i wrote:
procedure TForm1.FormPaint(Sender: TObject);
var b1,b2:TBitmap;
begin
b1 := TBitmap.Create;
b1.SetSize(20,20);
b1.Canvas.Brush.Color := clBlue;
b1.Canvas.Rectangle(0,0,20,20);
Canvas.Draw(10,10,b1,$ff);
Canvas.Draw(40,10,b1,$66);
b2 := TBitmap.Create;
b2.Transparent := true;
b2.TransparentColor := clFuchsia;
b2.Canvas.Brush.Color := clFuchsia;
b2.SetSize(20,20);
b2.Canvas.Brush.Color := clBlue;
b2.Canvas.Ellipse(0,0,20,20);
Canvas.Draw(10,40,b2,$ff);
Canvas.Draw(40,40,b2,$66);
b1.Free;
b2.Free;
end;
produces:

How could I draw (for example, a blue circle) with a transparent background and opacity of only 40%?
I would prefer a solution without direct winapi (e.g. bitblt, ...) if possible.
I tried several hacks, such as the alpha channel bitrate, to the TColor value, but it did not work.
here i am what i tried:
procedure TForm1.FormPaint(Sender: TObject);
var b:TBitmap;
begin
b := TBitmap.Create;
b.PixelFormat := pf32bit;
b.AlphaFormat := afDefined;
b.Canvas.Brush.Color := 0 and ($ff shl 32); // Background Transperency
b.SetSize(20,20);
b.Canvas.Brush.Color := clBlue + (($ff-$66) shl 32);
b.Canvas.Ellipse(0,0,20,20);
Canvas.Draw(10,10,b);
b.Free;
end;
produces:

early!
EDIT: : delphi xe 5 Windows 7 64bit ( 32- )