Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Save and retrieve a graph

Posted on 2000-02-21
3
Medium Priority
?
202 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 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

722 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