Solved

Plotting pixels in Windows using Visual C++

Posted on 1998-12-09
7
823 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
[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
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
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 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

Technology Partners: 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!

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

617 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