fumita
asked on
Plotting pixels in Windows using Visual C++
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!
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.)
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.)
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 ?
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 ?
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.)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
Can the array dimensions be fixed, or do you need them to vary at run-time?
Have you tried using new? if so what problem did you have?