Solved

Slow Plot

Posted on 1998-11-17
6
242 Views
Last Modified: 2010-05-18
I've created a control which basically just draws a trace according to data supplied to it.  It does this using the line(x1,y1)-(x2,y2) function.
Basic problem - it's slow.  I may have up to 32 of these updating continuously in my project, and with the possibility of 1000 data points - this can mean drawing tens of thousands of lines in each iteration - which I want to happen once every two seconds or so.

So, what can anybody suggest?  Is there a better way of drawing these lines which goes faster?  I was hoping I may be able to get each instance of my control to work in parallel using multithreading, but I can't figure it out.

Cheers-
Rob
0
Comment
Question by:robholden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:kswinney
ID: 1445220
You can use the API calls "MoveTo" and "LineTo" which will draw significantly faster than VB's line method... but you might also try "Polygon" which will draw several line segments at once.

HTH.
0
 

Author Comment

by:robholden
ID: 1445221
I found LineTo and MoveToEx in the WIN32API.  However I can't seem to get them to work.  The API seems to have loads of graphics type calls, its quite overwhelming.  Could you post a bit of sample code to give me a starting point please?

Cheers
0
 

Author Comment

by:robholden
ID: 1445222
Ok, anybody else got any ideas?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:muffinthedog
ID: 1445223
Seems you might be able to use a memory DC and just BitBlt or StretchBlt it to where ever. Have some old code somewhere (not for a plot though) if you would like... May B write a leetle Dee el el function, pass an array and a hwnd, and have it update the window?
0
 
LVL 1

Accepted Solution

by:
javierma earned 100 total points
ID: 1445224
        I'd try using the API function Polyline. It's easy to do:
1) Declare the function in a module (just paste this)
Type POINTAPI
     x As Long
     y As Long
End Type
Declare Function Polyline& Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long)

2) Create a POINTAPI vector to store your points: (10 for example)
Dim ptVector(1 to 10) as POINTAPI

3) Call the function telling it how many points from that vector are you going to paint.
If you're going to paint in a form then hdc = MyForm.hdc; if on a PictureBox hdc = MyPicture.hdc; or if on a printer hdc = Printer.hdc
Dim Foo as Long
foo = Polyline(hdc , ptVector(1) , 10 )

You're all set. If foo = 0 it means that the function failed, otherwise it worked.

                  Javier Martinez

0
 

Author Comment

by:robholden
ID: 1445225
I like this solution - it is seriously fast.

Cheers-
Rob
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question