How do I make a TBitmap transparent when loading it from a resource

138 views Asked by At

I am trying to load a TBitmap from resources while keeping it transparent. Even with the transparent Property enabled it still looks the same.

What I tried to do:

procedure TMovie.BitBtn1Click(Sender: TObject);
var
 BitMap1 : TBitMap;
begin
  BitMap1 := TBitMap.Create;

  BitMap1.Transparent := TRUE;
  BitMap1.TransparentColor := clBlack;

  try
    BitMap1.LoadFromResourceName(HInstance,'Bitmap_2');
    Star_2.Picture.Assign(Bitmap1);
  finally
    BitMap1.Free;
  end;
end;
1

There are 1 answers

3
Antonio Petricca On

You should try to invert transparency properties as follow:

procedure TMovie.BitBtn1Click(Sender: TObject);
var
 BitMap1 : TBitMap;
begin
  BitMap1 := TBitMap.Create;
  
  try
    BitMap1.LoadFromResourceName(HInstance,'Bitmap_2');

    BitMap1.Transparent := TRUE;
    BitMap1.TransparentColor := clBlack;

    Star_2.Picture.Assign(Bitmap1);
  finally
    BitMap1.Free;
  end;
end;