Recent

Author Topic: [RESOLVED] Proper Canvas LineTo and MoveTo  (Read 13832 times)

beefycoder

  • New Member
  • *
  • Posts: 24
[RESOLVED] Proper Canvas LineTo and MoveTo
« on: May 02, 2012, 07:05:02 pm »
I would like to draw simple lines using coordinates retrieved from hardware source (about 15000 to 20000 true/false points per second) to display logic level (scope-like view).

I chose TImage as simplest way of drawing while avoiding to draw directly to form itself.

I used simple code that is invoked on click event (Image1 is TImage):
Code: [Select]
with Image1 do
  begin
    Canvas.Pen.Color := clWhite;
    Canvas.Pen.Width := 1;
    Canvas.Pen.Style := psSolid;
    Canvas.MoveTo (0, 0);
    Canvas.LineTo (100, 100);
  end;

I get the white line, but whole Canvas is filled with black color. I tried searching for methods that suppress this or at least set complete transparency, and here in forums too.

There is no clear solution to this problem.

So, how to write code that draws only lines without affecting background ?
« Last Edit: May 04, 2012, 04:36:41 pm by beefycoder »

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Proper Canvas LineTo and MoveTo
« Reply #1 on: May 02, 2012, 07:12:17 pm »
Canvas.Clear;
Canvas.Brush.Color:= clGreen; {what color you want}
Canvas.Clear;
« Last Edit: May 02, 2012, 07:18:06 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

beefycoder

  • New Member
  • *
  • Posts: 24
Re: Proper Canvas LineTo and MoveTo
« Reply #2 on: May 02, 2012, 07:52:19 pm »
Thanks ! I hope TImage will soon have this bug solved soon.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Proper Canvas LineTo and MoveTo
« Reply #3 on: May 02, 2012, 09:43:46 pm »
@ (about 15000 to 20000 true/false points per second)

I'm not sure if TImage.Canvas is enough fast for this but I know here are more graphicly-experienced people on this forum.

Anyway, see this: http://wiki.freepascal.org/Fast_direct_pixel_access
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

beefycoder

  • New Member
  • *
  • Posts: 24
Re: Proper Canvas LineTo and MoveTo
« Reply #4 on: May 03, 2012, 08:35:36 am »
Direct access should work fine for this (as long as i dont' force my display to work at 15k frames/sec ;) )

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Proper Canvas LineTo and MoveTo
« Reply #5 on: May 03, 2012, 09:09:45 am »
Thanks ! I hope TImage will soon have this bug solved soon.

There is no bug. By design all TImage requires that you draw the entire available area. Not only the minimum that you want.

If you want to draw directly on the form use the TForm.OnPaint event

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Proper Canvas LineTo and MoveTo
« Reply #6 on: May 03, 2012, 11:05:56 am »
If you really want performance, software rendering doesn't have the punch! You can look into OpenGL too.

beefycoder

  • New Member
  • *
  • Posts: 24
Re: Proper Canvas LineTo and MoveTo
« Reply #7 on: May 04, 2012, 04:36:21 pm »
@felipemdc : So it's by design.


@User137 : I was thinking backwards about the whole thing. The display does not need such high performance.

Thanks for the all advice and help !

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: [RESOLVED] Proper Canvas LineTo and MoveTo
« Reply #8 on: May 04, 2012, 06:34:35 pm »
Have you looked at fpVectorial?

You could create a TvVectorialPage, and place a TPaintBox on your form, paint with DrawFPVectorialToCanvas.

 

TinyPortal © 2005-2018