• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Saving pict file after drawing with LineTo()

Hi. I wrote a program which draw inside a window using MoveTo() and LineTo().
How do I save the drawing obtained inside the window?
Actually, I'm a able to open a PICT file, to draw on it, and save it. But when I open it again (even in another software) , the file look unchanged. I'm using a PicHandle to open and save the file. I've been learning C on the Mac by myself, just by looking at other pieces of code. I hope that you can help me. Thank you.
  • 3
1 Solution
I belive this example code from Think Reference should help you out:

 * How to spool a Picture to a File
// Assumes inclusion of <MacHeaders>

pascal void PutPICTData(Ptr dataPtr, short byteCount);
void PictOut(void);

PicHandle      pHand2;
short      globalRef;

pascal void PutPICTData(Ptr dataPtr, short byteCount)
      long      longCount;

      longCount = byteCount;
      if (FSWrite(globalRef, &longCount, dataPtr) != noErr)
      if (pHand2)    /* Help QD take care of oddness in the picture */
        (**pHand2).picSize += longCount;

void PictOut()
      OSErr      err;
      short      i,
      Point      where;      /* where to display dialog */
      long      longCount,
      SFReply      reply;      /* reply record */
      CQDProcs      myProcs;

      CGrafPort      myPort;
      CGrafPtr      myPortPtr,

      Rect      myRect,

      myPortPtr = &myPort;       /* initialize */
      OpenPort(myPortPtr);      /* set my port */

      where.h = 20;
      where.v = 20;
      SFPutFile(where, "\pSave picture as: ", "\puntitled", nil, &reply);
      if (!reply.good)
      err = Create(reply.fName, reply.vRefNum, '????', 'PICT');
      if (err != dupFNErr && err != noErr)
      err = FSOpen(reply.fName, reply.vRefNum, &globalRef);
      if (err)
      pHand2 = nil;

      myPortPtr->grafProcs = &myProcs;
      myProcs.putPicProc = (Ptr)&PutPICTData;


      longZero = 0;
      longCount = 4;
      for (i = 1; i <= (512 + sizeof(Picture)) / 4; ++i)
                  err = FSWrite (globalRef, &longCount, &longZero);
      if (err)
      pHand2 = OpenPicture(&pictRect);

      DrawString("\pThis is a picture saved to disk");


      if (SetFPos(globalRef, fsFromStart, 512) != noErr)
      longCount = sizeof(Picture);
      if (FSWrite(globalRef, &longCount, *pHand2) != noErr)

      if (FSClose(globalRef) != noErr)

      myPortPtr->grafProcs = nil;

       KillPicture (pHand2);
} /* OutPICT */



Let me know if you have a problem with it.

supersaxAuthor Commented:
Unfortunately I was not able to make it work. There was a problem between converting CGrafPtr and GrafPtr which I solved by modifing in this way:
GrafPtr myPortPtr;

but I still have this problem:
Error: cannot convert
'char *' to
'pascal void (*)(char *, short)'
>QDProcs myProcs;
>myProcs.putPicProc = (Ptr)&PutPICTData;

The Think Reference code roov posted is mostly correct, but it predates the Routine Descriptor changes introduced when the PowerPC came out.

You want to change the line with the error to:
      myProcs.putPicProc = (QDPutPicUPP)&PutPICTData;

See the definition of CQDProcs in <Quickdraw.h> for how to update the Think Reference code if you use any of the other bottleneck procs.
supersaxAuthor Commented:
Thank you, both boonstra and roov.
I was able to work with the code after the change proposed by boonstra. However, when I hope the Pict file in Photoshop, PHotoshop says: "This does not appear to be a valid Quick Draw file. Attempt to open it anyway?". And if I say "Ok", Photoshop is able to open it. Maybe I should change "QDProcs" back to "CQDProcs", and both "GrafPort","GrafPtr" to "CGrafPort","CGrafPtr".
supersaxAuthor Commented:
I changed the code a little bit. Now I'n writing also the first 512 of data, and no longer it is giving me problems.

Since MoveTo() and LineTo() act exactly like if you are giving orders to a plotter to draw, I was wondering if it is not too difficult to save the image as an .eps file, or eventually as HPGL or Illustrator.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now