• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

API lineto

Hi,

I draw many lines by the Line method and found that is too slow.
Do you think the API lineto function will be faster?
0
victorlong
Asked:
victorlong
  • 3
  • 3
  • 2
  • +2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
The poor performance isn't caused by the Line method. It is due Windows itself.

Try setting the AutoRedraw property of your form to False.
0
 
VbmasterCommented:
Perhaps this can help make it faster, it made it really faster for me. You can add this to your form and set the Redraw property to False before you draw the lines and True when you are done..

Private m_Redraw As Boolean
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Property Let Redraw(RedrawState As Boolean)

  If (m_Redraw <> RedrawState) Then
    m_Redraw = RedrawState
    Call SendMessage(Me.hwnd, &HB, -m_Redraw, 0&)
    If m_Redraw Then Me.Refresh
  End If

End Property
0
 
Erick37Commented:
API LineTo will be faster than the Line method.  LineTo uses the current position to draw from, so in many cases you do not have to call MoveTo first.  In the Line method, the start and end positions are always given.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
VbmasterCommented:
Actually, you do not need to state the start positions with the VB Line either, you can for example use something like this ...

  Line (10, 10)-(200, 200), vbBlack
  Line -(400, 300), vbBlack

.... and it will continue from the current position on the second line.
0
 
victorlongAuthor Commented:
To Vbmaster:

I have just tested your code by adding an event

Private Sub Command1_Click()

 Me.Redraw = False
 Me.Line (0, 0)-(200, 200)
 Me.Redraw = True 'it made the line dissapeared!
 
End Sub

But, the line dissapeared.
0
 
Éric MoreauSenior .Net ConsultantCommented:
Do not use Redraw, use AutoRedraw!
0
 
victorlongAuthor Commented:
To emoreau:

Redraw is a property created for the form. Please see Vbmaster's comment.
0
 
Éric MoreauSenior .Net ConsultantCommented:
AutoRedraw is an already existing form's property that can help performance when using graphics method.
0
 
powlinCommented:
Line is more slow than any line drawing
i have done an appz that draw a rotating wireframe cube

in this case the LineTo is about 40-50% faster than Line you can also use PolyLineTo that draw line from an array point if your line segments is connected.

Setting autoredraw to false also speed up display but it looking flickering so Autoredraw is slower but appear more smooth.

0
 
victorlongAuthor Commented:
Experts,

Thank you for all your help.

I have just tested the speed in three cases:

API MovetoEx+Lineto: 14.75 seconds
VB Line: 15.16 seconds
VB Line+AutoRedraw/F/T: 16.37 seconds

So, only small difference :-(

In the loop of drawing lines, there are some calculation.....

I remember, long time ago, I used a statement which let no gpraph action in the loop until another statement all the graph actions were executed. I can not remember the name of the statements and in VB or Delphi :-( Perhaps that can help me?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now