Solved

Saving pict file after drawing with LineTo()

Posted on 1999-01-26
5
276 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:supersax
  • 3
5 Comments
 
LVL 2

Expert Comment

by:roov
ID: 1291766
I belive this example code from Think Reference should help you out:


/* CODE EXAMPLE #1 */
/*
 * 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)
                  Debugger();
      if (pHand2)    /* Help QD take care of oddness in the picture */
        (**pHand2).picSize += longCount;
}

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

      CGrafPort      myPort;
      CGrafPtr      myPortPtr,
                              oldPort;

      Rect      myRect,
                              pictRect;

      GetPort(&oldPort);
      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)
                  Debugger();
      err = Create(reply.fName, reply.vRefNum, '????', 'PICT');
      if (err != dupFNErr && err != noErr)
                              Debugger();
      err = FSOpen(reply.fName, reply.vRefNum, &globalRef);
      if (err)
                  Debugger();
      pHand2 = nil;

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

      SetRect(&myRect,100,100,300,300);
      SetRect(&pictRect,0,0,500,500);

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

      MoveTo(5,10);
      DrawString("\pThis is a picture saved to disk");
      PaintRect(&myRect);

      ClosePicture();

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

      if (FSClose(globalRef) != noErr)
                  Debugger();

      myPortPtr->grafProcs = nil;

       KillPicture (pHand2);
      SetPort(oldPort);
} /* OutPICT */

main()
{
      InitGraf(&thePort);
      InitFonts();
      InitWindows();
      InitMenus();
      TEInit();
      InitDialogs(nil);
      InitCursor();

      PictOut();
}

Let me know if you have a problem with it.

0
 

Author Comment

by:supersax
ID: 1291767
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;
GetPort(&oldPort);

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


0
 
LVL 3

Accepted Solution

by:
boonstra earned 200 total points
ID: 1291768
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.
0
 

Author Comment

by:supersax
ID: 1291769
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".
0
 

Author Comment

by:supersax
ID: 1291770
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.
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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 42
VB.NET how to use the Vertical ScrollBar 5 114
child constructor and parent constructor, overriding and overloading 6 88
wordappend challenge 8 200
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

829 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