Recent

Author Topic: bgrabitmap with by real tarnsparent paint  (Read 9459 times)

ali-libre

  • New Member
  • *
  • Posts: 40
bgrabitmap with by real tarnsparent paint
« on: October 07, 2016, 03:00:28 pm »
Code: Pascal  [Select][+][-]
  1. Grid.Draw(Canvas, 0, 0, True);
  2. Graph.drawlineantialias(...);
  3. Graph.Draw(PaintBox1.Canvas, 0, 0, False);
  4. Grad.Draw(PaintBox1.canvas, 0,0, False);   //or true  
             
this will pruduce pic1
but i'm want secount pic (pic2)
« Last Edit: October 07, 2016, 03:04:30 pm by ali-libre »

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: bgrabitmap with by real tarnsparent paint
« Reply #1 on: October 07, 2016, 07:45:11 pm »
Is it that you are drawing a grid with one BGRABitmap called Grid and then you are drawing a graph with another BGRABitmap called Graph?

Can you give more detail on the code you are using in on Graph?
Conscience is the debugger of the mind

ali-libre

  • New Member
  • *
  • Posts: 40
Re: bgrabitmap with by real tarnsparent paint
« Reply #2 on: October 07, 2016, 07:53:29 pm »
tird line aren't important
im just try to (in mean word -really) clear/erase by alpha or transprent value a part of paintbox.
that's just all i'm want to do
sorry for bad english...

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: bgrabitmap with by real tarnsparent paint
« Reply #3 on: October 07, 2016, 08:03:02 pm »
tird line aren't important
im just try to (in mean word -really) clear/erase by alpha or transprent value a part of paintbox.
that's just all i'm want to do
sorry for bad english...

Wich language you speak?

You can try to install BGRA Controls and use BGRA Virtual Screen, so you have direct access to a Bitmap property that is in fact a BGRA Bitmap, and you no need to worry to draw it to a canvas, that is done automatically.

The main problem here is that as circular said we need more info, maybe a part of your code.

I understand you want to clear a part of the line you're drawing, but maybe you can draw two separate lines instead of erasing the line.

ali-libre

  • New Member
  • *
  • Posts: 40
Re: bgrabitmap with by real tarnsparent paint
« Reply #4 on: October 07, 2016, 08:25:19 pm »
 :-[ i'm sorry
thank's
no. i must to clear apart of paintbox not draw seprate line
the code has nothing to say...
Code: Pascal  [Select][+][-]
  1.   Graph := TBGRABitmap.Create(800,180,BGRA(0,0,0,0));
  2.   Graph.DrawLineAntialias(0,0,990,180,BGRA(0,255,0),3);
  3.   GRAD := TBGRABitmap.Create(470,217,BGRA(0,0,0,0));
  4.   GRAD.AlphaFillRect(200,0,272,217,50);
  5.   bmp := TBGRABitmap.Create(990,180,ColorToBGRA(Form1.color));
  6.   tex := TBGRABitmap(bmp.CreateBrushTexture(bScross,BGRA(S_Color_GS,S_Color_GS,0),ColorToBGRA(Form1.color,0),6,6,1));
  7.   tex2 := TBGRABitmap(bmp.CreateBrushTexture(bScross,BGRA(S_Color_GB,S_Color_GB,100),BGRA(0,0,0,0),30,30,1));
  8.   bmp.FillRoundRectAntialias(0,-3,990,178,30,30,tex,[rrDefault]);
  9.   bmp.FillRoundRectAntialias(0,0,990,180,30,30,tex2,[rrDefault]);
  10.   bmp.FillRect(40,0,80,180,tex,dmset);
  11.   bmp.FillRect(40,0,80,180,tex2,dmSetExceptTransparent);
  12.   bmp.Draw(Canvas,600,20, false);
  13.   Graph.Draw(PaintBox1.Canvas,0,0, True);
  14.   GRAD.Draw(PaintBox1.Canvas,0,0, False);        
  15.  
recently i draw big area with no performance
now i'm want to clear apart and redaraw
it will reduce completly big drawing time
it run on raspery-pi
« Last Edit: October 07, 2016, 08:38:24 pm by ali-libre »

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: bgrabitmap with by real tarnsparent paint
« Reply #5 on: October 07, 2016, 09:34:03 pm »
Ok I guess I understand.

The Canvas does not have transparency, so you cannot make it transparent with AlphaFill.

When you do GRAD.AlphaFillRect, it changes the alpha value to 50, so that it becomes a black transparent rectangle.

If you just want to replace a part of the image, you can instead use a BGRABitmap that has the size of the part you want to replace and draw it on the canvas.

For this you need to avoid having a transparent background. When you create your bitmaps, create them with BGRABlack color instead of BGRA(0,0,0,0).

So that when you draw it, it replaces completely the area covered by the BGRABitmap.
Conscience is the debugger of the mind

ali-libre

  • New Member
  • *
  • Posts: 40
Re: bgrabitmap with by real tarnsparent paint
« Reply #6 on: October 07, 2016, 10:42:07 pm »
thank's again..
i have draw grid under the paintbox & i dont want redraw it again
becuase of this i want fill a part by transpaernt
while the whole of drawing time are to fill by texture
(((((keep in mind bgrabitmap have a bad texture filing(it need more peroperty/option to fill texture)  )))))
and if bgrabitmap can't do that... how can i do that..?
thank's in advance...

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: bgrabitmap with by real tarnsparent paint
« Reply #7 on: October 07, 2016, 10:57:54 pm »
Please provide a code that can be compiled, that code has missing the grid and some variables.

And exactly what you want to do, what you need to draw (not a test, the real thing) and why you think is slow.

ali-libre

  • New Member
  • *
  • Posts: 40
Re: bgrabitmap with by real tarnsparent paint
« Reply #8 on: October 08, 2016, 08:08:23 pm »
Code: Pascal  [Select][+][-]
  1. unit paint;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,BGRABitmap,BGRABitmapTypes;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)                                
  15.     DrawTimer: TTimer;
  16.     procedure FormClick(Sender: TObject);
  17.     procedure FormCreate(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.     procedure OnPaint(sender: TObject);
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.   TData: array [0..63]of Integer =(88,96,104,112,120,127,134,140,146,151,156,160,163,166,167,168,168,168,166,164,161,158,153,148,143,136,130,123,115,108,100,92,84,76,68,60,53,46,40,33,28,23,19,15,12,10,9,9,9,10,12,14,18,22,27,32,38,44,51,59,66,74,82,88);
  27.   Pos,Poss: Integer;
  28.   FirstTime: Byte = 1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. begin
  38.   Pos := 1;
  39.   Poss := 1;
  40.   Form1.Width:=1010;
  41.   Form1.Height:=210;
  42.   DrawTimer := TTimer.Create(Self);
  43.   DrawTimer.Enabled:= False;
  44.   DrawTimer.Interval:= 83;
  45.   DrawTimer.OnTimer:= @OnPaint;
  46. end;
  47.  
  48. procedure TForm1.FormClick(Sender: TObject);
  49. begin
  50.   DrawTimer.Enabled:= True;
  51. end;
  52.  
  53. procedure TForm1.OnPaint(sender: TObject); inline;
  54. var
  55.   tex,tex2,bmp: TBGRABitmap;
  56.   e: Byte = 0;
  57.   td: TDateTime;
  58.   h,m,s,ms: word;
  59. begin
  60.   td := Now;
  61.   bmp := TBGRABitmap.Create(1000,200,BGRA(0,0,0,0));
  62.   tex := TBGRABitmap(bmp.CreateBrushTexture(bScross,BGRA(28,28,0),BGRA(0,0,0),6,6,1));
  63.   tex2 := TBGRABitmap(bmp.CreateBrushTexture(bScross,BGRA(84,84,100),BGRA(0,0,0,0),30,30,1));
  64.   if FirstTime = 1 then
  65.   begin
  66.     FirstTime := 0;
  67.     bmp.FillRoundRectAntialias(0,0,1000,200,30,30,tex,[rrDefault],false);
  68.     bmp.FillRoundRectAntialias(0,0,1000,200,30,30,tex2,[rrDefault]);
  69.   end;
  70.   for e := 0 to 4 do
  71.   begin                        
  72.     if Pos >= 63 then Pos := 1;
  73.     bmp.DrawLineAntialias(poss+10,TData[pos]+10,poss+11,TData[pos+1]+10,BGRA(0,255,0), 2);
  74.     Poss := Poss + 1;
  75.     Pos := Pos + 1;
  76.   end;
  77.   bmp.FillRect(15+Poss, 0, poss+22, 200, tex, dmSet);
  78.   bmp.FillRect(15+Poss, 0, poss+22, 200, tex2, dmSetExceptTransparent);
  79.   if 32+Poss >= 990 then
  80.   begin
  81.     Poss := 10;
  82.     bmp.FillRectAntialias(9, 0, 32, 200, tex);
  83.     bmp.FillRectAntialias(9, 0, 32, 200, tex2);
  84.   end;
  85.   bmp.Draw(Canvas,5,5, false);
  86.   bmp.Free;
  87.   tex.Free;
  88.   tex2.Free;
  89.   DecodeTime(Now - td, m,h,s,ms);
  90.   WriteLn(Format('draw took %.3d msec', [ ms]));
  91. end;
  92.  
  93. end.
  94.  
i'm beginner in pascal & class so it took time to rewrite old code
in my computer it took 2~4 ms or more
in rasp-pi(with END over-clocked cpu) it took 10-11 time than a pc
while i have 4 or more of this graph on a form...
it took ~125msec and more. so the fps will down to  6-7 and less
thank's
« Last Edit: October 08, 2016, 08:13:08 pm by ali-libre »

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: bgrabitmap with by real tarnsparent paint
« Reply #9 on: October 08, 2016, 09:03:23 pm »
Hmm.. well if you have a shape that does not change, you can prepare it in a bitmap when the form is created, and then you can put it as such on another bitmap.
Conscience is the debugger of the mind

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: bgrabitmap with by real tarnsparent paint
« Reply #10 on: October 08, 2016, 09:51:01 pm »
Here it is. It takes 0 ms for drawing. See attachment.

ali-libre

  • New Member
  • *
  • Posts: 40
Re: bgrabitmap with by real tarnsparent paint
« Reply #11 on: October 08, 2016, 10:16:45 pm »
thank's thank's thank's ....
many thank's
however it take 0~2msec to draw nothing...!
it doesn't show anything really...
is there any project option i must apply...?
« Last Edit: October 08, 2016, 10:45:47 pm by ali-libre »

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: bgrabitmap with by real tarnsparent paint
« Reply #12 on: October 08, 2016, 10:58:53 pm »
thank's thank's thank's ....
many thank's
however it take 0~2msec to draw nothing...!
it doesn't show anything really...
is there any project option i must apply...?

I'm using FPC and lazarus trunk on windows, not 1.6 so I can't say why you can't see it.

Edit: works only on Windows, I remember that you can draw only OnPaint event in other OS's. But this code works under Windows.

Edit2: Here it is a working code for Linux, but is not as faster as can be under Windows because there is no way (as far as I know) to invalidate just a part of the window.
« Last Edit: October 08, 2016, 11:08:06 pm by lainz »

ali-libre

  • New Member
  • *
  • Posts: 40
Re: bgrabitmap with by real tarnsparent paint
« Reply #13 on: October 09, 2016, 02:58:44 am »
 :o no. why in linux is differ...?
is there any option for texture starting point etc... optin ?
i'm try to change start position of tex but every time got same result...
i'm using trunk version of fpc & lazarus..
thank's again

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: bgrabitmap with by real tarnsparent paint
« Reply #14 on: October 09, 2016, 08:34:07 am »
@ali-libre: to change the offset of the texture, you can set in the texture the ScanOffset property. I suppose you are changing the ScanOffset property in the destination bitmap instead of the texture bitmap.

Something else, instead of doing TBGRABitmap.Create(CreateBrushTexture(...)) which does a memory leak, you can write TBGRABitmap(CreateBrushTexture(...)) or simply store the texture in a variable of type TBGRACustomBitmap.

@lainz: Yes it is possible to invalidate a part of a window that works on both Linux and Windows. It is the function InvalidateRect in LCLIntf unit that can be used as follows. On Windows it points to winapih.inc and on Linux it points to somewhere else.
Code: Pascal  [Select][+][-]
  1. InvalidateRect(Handle,@area,False);
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018