Author Topic: Transparency bug, ? [SOLVED]  (Read 3754 times)


  • New Member
  • *
  • Posts: 11
Transparency bug, ? [SOLVED]
« on: November 08, 2010, 05:41:20 pm »
Hello, I've got this serious problem which stopped me from developing my game, and I hope someone can help me.
I made example which is attached in this thread.

1. Basic point is, we draw a certain bitmap with transparent areas into some image. Everything is fine, transparent places are 'transparent'.

2. Then we change the bitmap a bit. We draw some more transparent stuff into it.

3. We again draw bitmap into image. New transparent things are not transparent, but the ones which were there first are.

Any idea how to get around this or possibly fix it ?

Thanks for any input.

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
  Bmp1: TBitmap;
  // Simple bitmap with white background and yellow circle in it
  // It is transparent with color white so white background doesn't show
  Bmp1 := TBitmap.Create;
  Bmp1.TransparentColor := clWhite;
  Bmp1.Transparent := true;
  Bmp1.Canvas.Brush.Color := clWhite;

  // Now we draw into bitmap yellow ellipse with white(transparent) rectangle
  Bmp1.Canvas.Brush.Color := clYellow;
  Bmp1.Canvas.Brush.Color := clWhite;

  // Now we render it and see everything works fine. There is yellow circle
  // with black box in it (which was white rect, but due to transparency
  // you can see through)
  Img.Canvas.Brush.Color := clBlack;
  Img.Canvas.Draw(50,50, Bmp1);

  // But now, we add red elipse
  Bmp1.Canvas.Brush.Color := clRed;

  // With again white rect, which should be transparent and we
  // should see through black color
  Bmp1.Canvas.Brush.Color := clWhite;

  // We draw it, but it's not transparent!
  Img.Canvas.Brush.Color := clBlack;
  Img.Canvas.Draw(50,50, Bmp1);

« Last Edit: November 08, 2010, 07:28:27 pm by MarsTeam »


  • New Member
  • *
  • Posts: 11
Re: Transparency bug, ?
« Reply #1 on: November 08, 2010, 07:28:17 pm »
Well after hours and hours of trying, I found out where the problem was.

After Bmp1 is drawn into image, we need to reset it's MaskHandle

Bmp1.MaskHandle :=0

Then it will work.


TinyPortal © 2005-2018