Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: Dibo on September 26, 2012, 07:21:48 pm

Title: [SOLVED] Draw repeated
Post by: Dibo on September 26, 2012, 07:21:48 pm
Hi,

I'm wondering. Exists any DrawRepeated method in bgrabitmap? I have small pattern and want fill it on whole canvas. I know how to do it manually but maybe BGRABitmap have this funcionality

Regards
Title: Re: Draw repeated
Post by: lainz on September 26, 2012, 09:51:13 pm
procedure Fill(texture: IBGRAScanner; mode: TDrawMode); override;
Title: Re: Draw repeated
Post by: circular on September 26, 2012, 10:33:25 pm
Yes, and you can draw any shape (FillRect, FillPoly, etc.) with a texture as a parameter.
Title: Re: Draw repeated
Post by: circular on September 26, 2012, 10:43:31 pm
And you can even use scanners to distort the result. See :
http://wiki.freepascal.org/BGRABitmap_tutorial_11
Title: Re: Draw repeated
Post by: Dibo on October 02, 2012, 07:13:16 pm
Thanks!

BTW: What is in TBGRABitmap.Bitmap? I created small pattern and want use it as a brush in Canvas.Brush.Bitmap to speed up fill canvas. Look at b type:

This code work:
Code: Pascal  [Select]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var
  3.   b: TBitmap;
  4.   x,y,t: Integer;  
  5. begin
  6.   t := GetTickCount;
  7.  
  8.   b := TBitmap.Create;
  9.   b.SetSize(5,5);
  10.   for x:=0 to b.Width-1 do
  11.     for y:=0 to b.Height-1 do
  12.       if ((x+y) mod 5=0) or ((y-x) mod 5=0) then
  13.         b.Canvas.Pixels[x,y] := RGBToColor(0, 0, 0) // Black
  14.       else
  15.         b.Canvas.Pixels[x,y] := RGBToColor(40, 40, 40); // Some dark shade of gray
  16.  
  17.   Canvas.Brush.Bitmap := b;
  18.   Canvas.FillRect(ClientRect);
  19.   Canvas.Brush.Bitmap := nil;
  20.  
  21.   b.Free;
  22.  
  23.   Self.Caption := IntToStr(GetTickCount-t);
  24. end;  
  25.  

And this (with TBGRABitmap) doesn't:
Code: Pascal  [Select]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. var
  3.   b, bmp: TBGRABitmap;
  4.   x,y,t: Integer;
  5. begin
  6.   t := GetTickCount;
  7.  
  8.   b := TBGRABitmap.Create(5,5);
  9.   for x:=0 to b.Width-1 do
  10.     for y:=0 to b.Height-1 do
  11.       if ((x+y) mod 5=0) or ((y-x) mod 5=0) then
  12.         b.CanvasBGRA.Pixels[x,y] := RGBToColor(0, 0, 0) // Black
  13.       else
  14.         b.CanvasBGRA.Pixels[x,y] := RGBToColor(40, 40, 40); // Some dark shade of gray
  15.  
  16.   b.InvalidateBitmap;
  17.   Canvas.Brush.Bitmap := b.Bitmap;
  18.   Canvas.FillRect(ClientRect);
  19.   Canvas.Brush.Bitmap := nil;
  20.   b.Free;
  21.  
  22.   Self.Caption := IntToStr(GetTickCount-t);
  23. end;
  24.  
Title: Re: Draw repeated
Post by: circular on October 02, 2012, 10:09:13 pm
Thanks!

BTW: What is in TBGRABitmap.Bitmap?
It should be a TBitmap containing the current bitmap.

I dont know why it does not work. What if you use SetPixel instead ? And MakeBitmapCopy instead of Bitmap ?
Title: Re: [SOLVED] Draw repeated
Post by: Dibo on October 02, 2012, 10:38:05 pm
MakeBitmapCopy solved problem. Thanks!