Recent

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

MarsTeam

  • 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);
var
  Bmp1: TBitmap;
begin
  // 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.Width:=300;
  Bmp1.Height:=300;
  Bmp1.TransparentColor := clWhite;
  Bmp1.Transparent := true;
  Bmp1.Canvas.Brush.Color := clWhite;
  Bmp1.Canvas.FillRect(Rect(0,0,Bmp1.Width,Bmp1.Height));

  // Now we draw into bitmap yellow ellipse with white(transparent) rectangle
  Bmp1.Canvas.Brush.Color := clYellow;
  Bmp1.Canvas.Ellipse(50,50,200,200);
  Bmp1.Canvas.Brush.Color := clWhite;
  Bmp1.Canvas.Rectangle(80,80,100,100);

  // 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.FillRect(Img.ClientRect);
  Img.Canvas.Draw(50,50, Bmp1);

  // But now, we add red elipse
  Bmp1.Canvas.Brush.Color := clRed;
  Bmp1.Canvas.Ellipse(120,120,170,170);

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

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

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

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