Recent

Author Topic: How to draw Rectangle in TBGRAVirtualScreen.ReDraw  (Read 3305 times)

freeman35

  • Jr. Member
  • **
  • Posts: 92
How to draw Rectangle in TBGRAVirtualScreen.ReDraw
« on: September 29, 2014, 04:08:45 pm »
in TBGRAVirtualScreen.ReDraw:
Bitmap.CanvasBGRA.Rectangle(FNewRect, False); "Filled" Parameter is False but still draw in Rectangle

question is:
How to draw just Rectangle lines in BGRA?
Example code for TImage

Code: [Select]
   with Bitmap.Canvas do begin
      Pen.Mode := pmNotXOR;
      Pen.Color := clBlue;
      Pen.Width := 3;
      with FNewRect do Rectangle(Left, Top, Right, Bottom);
   end;

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: How to draw Rectangle in TBGRAVirtualScreen.ReDraw
« Reply #1 on: September 29, 2014, 11:24:52 pm »
Ah I guess that's a bug. I have applied some fix on subversion.

You can in all cases draw just the frame by setting CanvasBGRA.Brush.Style := bsClear just as you would do with usual TCanvas.
Conscience is the debugger of the mind

freeman35

  • Jr. Member
  • **
  • Posts: 92
Re: How to draw Rectangle in TBGRAVirtualScreen.ReDraw
« Reply #2 on: October 01, 2014, 10:50:22 am »
Thank you very much, this code(s) working for me.

Code: [Select]
Bitmap.PutImage(0, 0, content, dmDrawWithTransparency);
with FNewRect do begin
   if (left>0)and(Right>0)then begin
    //Bitmap.CanvasBGRA.Pen.Color := clBlue;
    //Bitmap.CanvasBGRA.Pen.Width := 3;   
   //Bitmap.CanvasBGRA.Rectangle(FNewRect, False); //--> Fixed

    Bitmap.CanvasBGRA.Brush.Style := bsClear;
    with Bitmap.Canvas do begin
       Pen.Mode := pmNotXOR;
       Pen.Color := clBlue;
       Pen.Width := 3;
       Rectangle(Left, Top, Right, Bottom);
    end;
   end;
 end;

And I found different way too :)
Code: [Select]
....
var   FNewRect : TRect;
......
content := TBGRABitmap.Create('imga.bmp');
.....
procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
var ctx: TBGRACanvas2D;
begin
  ctx := Bitmap.Canvas2D;
  //ctx.antialiasing := False;
  Bitmap.PutImage(0, 0, content, dmDrawWithTransparency);
    if (FNewRect.left>0)and(FNewRect.Right>0)then begin
      ctx.lineWidth := 2;
      ctx.lineStyle([2,2]);
      ctx.strokeStyle(clBlue);
      ctx.strokeRect(FNewRect.Left, FNewRect.Top, FNewRect.Right, FNewRect.Bottom);
  end;
end;

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: How to draw Rectangle in TBGRAVirtualScreen.ReDraw
« Reply #3 on: October 03, 2014, 09:52:29 pm »
I would not recommend to use Bitmap.Canvas because it is more provided as a workaround in case you cannot use CanvasBGRA and can be slow.

Normally the following should do just fine:
Code: [Select]
   Bitmap.CanvasBGRA.Pen.Color := clBlue;
   Bitmap.CanvasBGRA.Pen.Width := 3;   
   Bitmap.CanvasBGRA.Brush.Style := bsClear;
   Bitmap.CanvasBGRA.Rectangle(FNewRect);

Or, even simpler:
Code: [Select]
   Bitmap.Rectangle(FNewRect, clBlue);
Or:
Code: [Select]
   Bitmap.RectangleAntialias(FNewRect.Left,FNewRect.Top,FNewRect.Right,FNewRect.Bottom, CSSBlue, 3);
« Last Edit: October 03, 2014, 09:54:24 pm by circular »
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018