Recent

Author Topic: [SOLVED] Draw repeated  (Read 4655 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
[SOLVED] Draw repeated
« 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
« Last Edit: October 02, 2012, 07:13:28 pm by Dibo »

lainz

  • Guest
Re: Draw repeated
« Reply #1 on: September 26, 2012, 09:51:13 pm »
procedure Fill(texture: IBGRAScanner; mode: TDrawMode); override;

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: Draw repeated
« Reply #2 on: September 26, 2012, 10:33:25 pm »
Yes, and you can draw any shape (FillRect, FillPoly, etc.) with a texture as a parameter.
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: Draw repeated
« Reply #3 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
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Draw repeated
« Reply #4 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.  
« Last Edit: October 02, 2012, 07:50:54 pm by Dibo »

circular

  • Hero Member
  • *****
  • Posts: 4195
    • Personal webpage
Re: Draw repeated
« Reply #5 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 ?
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: [SOLVED] Draw repeated
« Reply #6 on: October 02, 2012, 10:38:05 pm »
MakeBitmapCopy solved problem. Thanks!

 

TinyPortal © 2005-2018