Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save a CWGraph into a bitmap (.bmp) file in Visual C++?

I plot (chart) data into a graph control on a MFC dialog in Visual C++ and I need to save the image into a bmp file. I found the ControlImage method, but did not find any way to use it in Visual C++.
I would also like to retrieve the chart data (the point charted on the graph for each plot) and to use them to build data files. How to do it?
0 Kudos
Message 1 of 4
(5,002 Views)
Dealing with images in VC++ is far from easy. You would need to create the following objects: CBitmap, CArchive, CPictureHolder and a CDC.

Then call the SelectObject function on the CDC and pass in the CBitmap object. Then you can put the image of the graph in the CPictureHolder with:

ph.SetPictureDispatch((LPPICTUREDISP)m_CWGraph.ControlImage().m_lpDispatch);

where ph is the CPictureHolder and m_CWGraph is the CWGraph.

Then you can render the image to the bitmap CDC by calling the CPictureHolder::Render function. It will ask for the bounds of the picture in CRect form as well.

Then you can call the CBitmap.Serialize function with the CArchive object which should be pointing to the appropriate BMP file. Don't you just love MFC?

As for you second qu
estion, you can't retrieve the data that has been plotted to the graph. We don't maintain the data that is sent in because it would be very inefficient memory usage since data is usually decimated for display. I would recommend that you just send your data to a global buffer at the same time as plotting.

Best Regards,

Chris Matthews
Measurement Studio Support Manager
0 Kudos
Message 2 of 4
(5,002 Views)
Yes, far from easy. But will not work (and doesn't work, I tried).
The fact is that Serialize function cannot write the CObject (or better it does not write anything) on the file while I should write the Bitmap structures and then the bitmap data.
I did not find any api to write a bitmap image to disk, just load.
If you think your solution is the right way to follow, could you point me better on how to make it work?
0 Kudos
Message 3 of 4
(5,002 Views)
I am doing this very thing. See my article, http://www.codeproject.com/file/CDataFile.asp[^] on CP for more info.
0 Kudos
Message 4 of 4
(5,002 Views)