Recent

Author Topic: EraseLineAntialias not working  (Read 2926 times)

Pierrot

  • New member
  • *
  • Posts: 8
EraseLineAntialias not working
« on: April 23, 2014, 10:58:35 pm »
Hi there everyone!

I made a simplest example which must to draw a square on the BGRABitmap (I don't use layers for this case). Then, when mouse moves over the PaintBox component the line with mouse coordinates must to erase parts of the square, then put this bitmap layer (with transprency) on another layer (with white background) and then it together puts on the PaintBox.Canvas.  The problem is the EraseLineAntialias procedure works only once, when the form is created, it erases one line of the square, but it don't work when the mouse is moved over the PaintBox. Here is the code:

Code: [Select]
var
  Form1: TForm1;
  mainLayer: TBGRABitmap;
  resultLayer: TBGRABitmap;
  OriginX, OriginY: Integer;

...

procedure TForm1.FormCreate(Sender: TObject);
begin
  mainLayer:= TBGRABitmap.Create(256,256,BGRAPixelTransparent);
  mainLayer.FillRect(20,20,100,100,BGRA(255,0,0),dmDrawWithTransparency);

mainLayer.EraseLineAntialias(0,0,100,100,255,3,true); // It works here!!!

  resultLayer:= TBGRABitmap.Create(256,256,clWhite);
  resultLayer.PutImage(0,0,mainLayer,dmDrawWithTransparency);
  resultLayer.Draw(PaintBox1.Canvas,0,0,false);
end;

procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  mainLayer.EraseLineAntialias(OriginX,OriginY,x,y,255,3,true); //It don't works here!!!
  OriginX:=x;
  OriginY:=y;
  resultLayer.PutImage(0,0,mainLayer,dmDrawWithTransparency);
  resultLayer.Draw(PaintBox1.Canvas,0,0,false);
  //Label1.Caption:='x: '+IntToStr(x)+' y: '+IntToStr(y) ;
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  mainLayer.Free;
  resultLayer.Free;
end;
« Last Edit: April 24, 2014, 04:39:06 pm by Pierrot »

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: EraseLineAntialias not working
« Reply #1 on: April 24, 2014, 02:58:29 pm »
The problem is not with EraseLineAntialias, but that you need to fill the "resultLayer" with white before drawing the "mainLayer":

Code: [Select]
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  mainLayer.EraseLineAntialias(OriginX,OriginY,x,y,255,3,true); //It don't works here!!!
  OriginX:=x;
  OriginY:=y;
  resultLayer.Fill(BGRAWhite);
  resultLayer.PutImage(0,0,mainLayer,dmDrawWithTransparency);
  resultLayer.Draw(PaintBox1.Canvas,0,0,false);
end;
Conscience is the debugger of the mind

Pierrot

  • New member
  • *
  • Posts: 8
Re: EraseLineAntialias not working
« Reply #2 on: April 24, 2014, 04:37:37 pm »
Thanx a lot, circular! Now all works fine.

 

TinyPortal © 2005-2018