TBitmap draws a transparent image in Delphi 2009

Problem while drawing a translucent PNG image on a TBitmap object.

If TBitmap, HandleType is set to bmDDB, then the canvas becomes transparent. But the problem is that it does not work on all kinds of machines (for example: Windows on apple computers).

If the TBitmap HandleType property is set to bmDIB, the background canvas is drawn in white.

bmp.HandleType := bmDIB;

I tried setting Brush style to bsClear. But he draws transparent pixels in black.

How can I draw an image while maintaining its transparency and smooth curved edges.

Thanks Pavan.

+3
source share
1 answer

, bmDIB :

procedure TForm1.FormPaint(Sender: TObject);
var
  Bmp: TBitmap;
begin
  Bmp := TBitmap.Create;
  try
    Bmp.PixelFormat := pf32bit;
    Bmp.HandleType := bmDIB;
    Bmp.Width := 700;
    Bmp.Height := 400;
    Bmp.Transparent := TRUE;
    Bmp.TransparentColor := clMaroon;

    with Bmp.Canvas do begin
      Brush.Color := clMaroon;
      FillRect(Rect(0, 0, Bmp.Width, Bmp.Height));

      Brush.Color := clBlue;
      FillRect(Rect(42, 42, 200, 300));
    end;

    Canvas.Draw(12, 12, Bmp);
  finally
    Bmp.Free;
  end;
end;

, , TransparentColor.

, GDI ( ), - Graphics32.

+4

Source: https://habr.com/ru/post/1722765/


All Articles