Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
I met a question about the efficiency of GDI+.
There are several variables and methods
 as below:
1.points, such as A(Represents a coordinate point, such as X Y Z), B, C, D, E, etc.

2 List named Cmd1, used to add points by thread

3.paint method, in this method, the set of points connected to the line

4.thread for the constant addition of new points,such as F,G,H,I,J etc.

In Paint Method,i use g.DrawLine() to link a and b,c,d,e.
In thread,when i add new points,i will call invalid to refresh component.
so my question is,points become more and more, how can I maintain high efficiency, and redraw, 

do not start from the a point to re - drawline.


What I have tried:

VB
Sub DrawGLines2(g As Graphics)

        g.SmoothingMode = SmoothingMode.HighSpeed
        Dim Pen As New Pen(Brushes.White)
        Dim i As Int32
        'Dim c As Int32
        Dim preCmd1 As Cmd1
        Try
            For Each cmd As Cmd1 In Cmd1s            
                    Dim pfs() As PointF = cmd.PointFs.ToArray
                    If preCmd1 IsNot Nothing Then
                        g.DrawLine(Pen, cmd.PointFs(0), preCmd1.PointFs(0))
                    End If
                    preCmd1 = cmd
                End If
              
            Next
        Catch ex As Exception
            Debug.Print(ex.Message)
        End Try
    End Sub
------------------------------------------------------------
  Private Sub Sheet_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
      If Me.Cmd1s.Count>0 Then
            DrawGLines2(e.Graphics) 
        End If
    End Sub
-------------------------------------------------------------------------
    Public Sub AddPoint(x As Double, y As Double, z As Double, Optional G As Int32 = -1)
        Dim cmd1 As DrvSimu.Cmd1 = Nothing
        If cmd1 Is Nothing Then
            cmd1 = New DrvSimu.Cmd1
            Me.Cmd1s.Add(cmd1)
        End If

        Dim pf3d As New PointF3D(x, y, z)
        cmd1.PointF3Ds.Add(pf3d)

        Me.Invalidate()

    End Sub

thread will call AddPoint to add a,b,c,d,e points,and use invalid method to refresh,when i call invalid,the "For Each cmd As Cmd1 In Cmd1s" for each will begin from A point,so when points become more and more, how can I maintain high efficiency, and redraw, do not start from A point to re - drawline
Posted
Updated 26-Dec-16 15:15pm
v5
Comments
Richard MacCutchan 27-Dec-16 3:58am    
You need to create an algorithm to redraw only the parts that have changed, or are new.
xuyunhai20160827 28-Dec-16 0:58am    
Can you give me an example, this problem has troubled me for a long time
Richard MacCutchan 28-Dec-16 2:54am    
Sorry, I don't have an example. That's why I said "you need to ...".
xuyunhai20160827 28-Dec-16 4:18am    
If I know how to do it, I would have done it, then what is the idea of the algorithm。
How can I redraw the parts I need instead of re painting?
Richard MacCutchan 28-Dec-16 4:42am    
Go to Using GDI+ (Windows)[^], and Rectangles (Windows)[^] for information on using areas within a Window.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900