Solved

Plotting pixels in Windows using Visual C++

Posted on 1998-12-09
7
805 Views
Last Modified: 2013-12-14
 I'm writing a data acquisition program which takes an array of [512][512] data values for an image. One problem I'm having programming this in Visual C++ 6 on an NT platform is memory allocation for an array that large. The bigger problem I'm having is figuring out how to code a window that will display the 512x512 image and update it as fast as possible with realtime data from the data acquisition board. I could use help on allocating the array, plotting the pixels individually, or general tips on the best way to display each image and update it as fast as possible using an array or the individual pixels, either in a console or mfc application. Thanks for the help!
0
Comment
Question by:fumita
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1179757
Unless the data type is large, You should be able to allocate the array using new with no problem at all.  Assuming you are storing ints the array would be only about a meg.  No big deal.  For doubles it would be 2 meg, still no problem

Have you tried using new?  if so what problem did you have?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1179758
In what way is the image updated?  i.e how does it change with time?  does it scroll (like a storage scope, for example) or does the entire image change (like say a spectral graph).

Have you been able to handle the real-time data aquistion part?  That is the tough part.  If you have handled that, then displaying it won't be too bad (but you may have to be satisfied with updates that lag some.)
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1179759
I would suggest storing the array as a DIB (basically a block of memory with a handle to it, there's some MFC examples at www.codeguru.com). DIB = Device Independant Bitmap

The actual size to store this will depend on how many colors you need.
e.g.
Monochrome = 512 X 512 X 1 bits = 512 X 512 X 1  / 8 byes
16 color (4bits per pixel) = 512 X 512 X 4 bits = 512 X 512 X 4 / 8 bytes
etc.

The advantage of using a bitmap (DIB or DDB) is that you can throw whole sets of pixels to the screen using BitBlt

The advantage of using a DIB (as opposed to DDB) is that you can access the bitmap as a raw block of memory.

Lookup CreateDIBSection  API call.

Do you want specifics on DIBs or has codeguru the examples you need ?

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Expert Comment

by:nietod
ID: 1179760
That is probably the way to go, but maybe not.  For example, if speed is of the essence and if the plot changes only slightly with time (like if it scrolls) it may be better to work with the image right on the screen.  This is likely to give faster updates at times, although you may have to accept some limitations (like the fact that you might "loose"  parts of the image that are covered by a window or if part is uncovered by a window, it may take it longer to update it, that sort of thing.)
0
 
LVL 1

Accepted Solution

by:
Hans_Klose earned 100 total points
ID: 1179761
>One problem I'm having programming this in Visual C++ 6 on an >NT platform is memory allocation for an array that large.
 
The Array for 512x512 256 color array or bit map is only about a .25 Mb so with the flat memory model that is nothing.

 
>The bigger problem I'm having is figuring out how to code a >window that will display the 512x512 image and update it as >fast as possible with realtime data from the data acquisition >board.
Here you have  number of chices, you can for example
1) use SetPixelV of the CDC class.First set a rectangle in your client area for 512x512 for the display, then create your array of bytes, also create a 256 array of COLORREF, then just set the
dc.SetPixelV(indexX, indexY, arra[value_value_from_other_array))
(Do this if only few values change)
2) create two bitmaps, one is the visible surface and the other is created with CreateCompatibleBitmap(...) and is the buffer. Update the buffer then BitBlt(...) it to the visible surface.
(but do this only if many bits change in between the updates).
3) If you absolutly must have speed you can create a use DirectX to create a DirectDraw surface which memory you can update directly.(Lots of work but http://www.vcdj.com/vcdj/default.asp has a good tutorial)

>general tips on the best way to display each image and update >it as fast as possible using an array or the individual pixels, >either in a console or mfc application.
If your data is stored in some kind of a big class or struct don't store that directly, just store the array of bytes and convert the valure you want to plot.
0
 

Author Comment

by:fumita
ID: 1179762
Ok, thanks for the ideas.
When it comes to allocating the array with new, i've tried several methods, some of which have passed the compiling stage, but cause an exception due to a memory access violation when i try running the program. If I wanted to allocate an array of integers, size 512x512, what would be the best way to do that in C++? Using new, or a loop of mallocs? Could anyone give me a code example?

For the image updating, it will be taking real-time data from a micro-camera, so the image will be updated as an entire object, probabbly not pixel by pixel. thanks for the ideas with the bitmaps, i'm not too familiar with working with those, so i'll try and brush up on them and give it a shot.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1179763
Can the array dimensions be fixed, or do you need them to vary at run-time?
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now