Solved

Save and retrieve a graph

Posted on 2000-02-21
3
200 Views
Last Modified: 2010-04-10
How can  I save a graph? The graph is plotted using pDC->MoveTo and LineTo. It has text also which is written using pDC->TextOut command. I'm using AppWIzard for this program. Please guide me through each single step. Thanks.
0
Comment
Question by:kitlee
[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
3 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2542744
You could save the drawing operations using a windows meta file.  

I'm not familiar with the MFC way of dealing with metafiles, but it appears to be done through CMetaFileDC.
0
 
LVL 1

Expert Comment

by:nutsnuts
ID: 2542817
Which graph format do you want to save it as?
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 2544505
If you want to save your graph as a bitmap picture, then create a DIB bitmap (I like 24Bit DIBs as they are easier), select it into a CDC devicec context and then call your OnDraw code to draw onto the bitmap (just make sure your bitmap is big enough and/or that your drawing code is told how big to draw the graph).  Then, when finished, write the bitmap to a file.  This is not directly suported by windows, but there is sample code on the MSKB for how to write out DIB files.

Otherwise, just write out your data by serialising your document (which should be where you keep your data).  Then you can view the data by loading a document into your app.  Even nicer, when you build your app, make it an OLE server.  Then you can do things like embed your graphs in Word documents etc.

PS: For 24Bit DIB bitmaps, I have a class derived from CBitmap.  It has a member function to write the bitmap to a CFile.  This is the code I use...
      // setup file header
      BITMAPFILEHEADER hdr;
      hdr.bfType = 0x4d42;      // 0x42 = "B", 0x4d = "M"
      hdr.bfReserved1 = 0;
      hdr.bfReserved2 = 0;

      BITMAPINFOHEADER bitmapinfoheader;
      GetBITMAPINFOHEADER(bitmapinfoheader);

      // Compute the offset to the array of color indices.
      hdr.bfOffBits = (DWORD) (
            sizeof(BITMAPFILEHEADER) +
            bitmapinfoheader.biSize +
            bitmapinfoheader.biClrUsed * sizeof (RGBQUAD)
      );

      // Compute the size of the entire file.
      hdr.bfSize = hdr.bfOffBits + bitmapinfoheader.biSizeImage;

      bool ok = false;
      TRY {
            // Copy the BITMAPFILEHEADER into the .BMP file.
            file.WriteHuge(&hdr,sizeof(hdr));
            // Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
            file.WriteHuge(&bitmapinfoheader,sizeof(bitmapinfoheader) + bitmapinfoheader.biClrUsed * sizeof (RGBQUAD));
            // Copy the array of color indices into the .BMP file.
            file.WriteHuge(m_pBits,bitmapinfoheader.biSizeImage);

            ok = true;
      } CATCH_ALL (e) {
      } END_CATCH_ALL
      return ok;

If you want a graphic formats other than BMP files, then you'll probably need a third party graphics library (or track down some source code).

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

734 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