wrp@biochsn.acc.virginia.edu (William R. Pearson) (05/18/88)
I would like to make some plots in a program as a PICT, and then write them out to a file for later editing with MacDraw or SuperPaint. I have Programmer's Extender Vol II, which has ReadPict() and WritePict() functions (without source), but I would like to do it myself. Given a PicHandle, how does one write a PICT file that can be edited by a drawing program? Pointers to appropriate references will be appreciated. Bill Pearson
dorourke@polyslo.UUCP (David M. O'Rourke) (05/19/88)
In article <397@hudson.acc.virginia.edu> wrp@biochsn.acc.Virginia.EDU (William R. Pearson) writes: > Given a PicHandle, how does one write a PICT file that can be >edited by a drawing program? Pointers to appropriate references will be >appreciated. Heres some pascal style code that might help. This assumes that you've already generated the picture and have a valid handle to play with. function WritePicture (thePictHandle : PicHandle): BOOLEAN; var FileErr : OSErr; PictLength : LONGINT; FileRefNum : INTEGER; FileRecord : SFReply; PutFilePoint : Point; FileFndrInfo : FInfo; begin {First we need to get a File Name from the user. To do this we're going} {to use the standard file package from Volume I of inside Mac. I have put constants in some position that should be variables, please extend this code to calculate screen position, prompt, ect. at run time, for now this illustrates the concept} PutFilePoint.v := 30; PutFilePoint.h := 50; {This value really should be calculated based on the screen size from ScreenBits.bounds} SFPutFile(PutFilePoint, 'Please type a file Name', 'PictFile.pict', nil, FileRecord); {Now that we have an output file name, and record lets use it} FileErr := GetFInfo(FileRecord.fName, FileRecord.vRefNum, FileFndrInfo); if FileErr = fnfErr then begin FileErr := Create(FileRecord.fName, FileRecord.vRefNum, YourCreator, 'PICT'); if FileErr <> noErr then begin Do_Something_To_Report_the_problem; end; {if FileErr <> noErr} end {if FileErr = fnfErr} else begin FileFndrInfo.Type := 'PICT'; FileErr := SetFInfo(FileRecord.fName, FileRecord.vRefNum, FileFndrInfo); end; {else} FileErr := FSOpen(FileRecord.fName, FileRecord.vRefNum, FileRefNum); if FileErr <> noErr then begin Do_Something_To_Report_the_problem; end; {if FileErr <> noErr} FileErr := SetFPos (FileRefNum, fsFromStart, 0); if FileErr <> noErr then begin Do_Something_To_Report_the_problem; end; {if FileErr <> noErr} PictLength := GetHandleSize(Handle(thePictHandle)); HLock(Handle(thePictHandle)); FileErr := FSWrite(FileRefNum, PictLength, @thePictHandle^^); if FileErr <> noErr then begin Do_Something_To_Report_the_problem; end; {if FileErr <> noErr} FileErr := SetEOF(FileRefNum, PictLength); if FileErr <> noErr then begin Do_Something_To_Report_the_problem; end; {if FileErr <> noErr} HUnLock(Handle(thePictHandle)); FileErr := FSClose(FileRefNum); if FileErr <> noErr then begin Do_Something_To_Report_the_problem; end; {if FileErr <> noErr} if FileErr = noErr then WritePicture := True else WritePicture := False; {Set the value of the function to indicate success/falure} end; {WritePicture} This codes isn't perfect, but it should give you a rough idea about how to approach the problem. As far as readings go I'd recommend that you check chapter 20 of vol I, chap. 5 of volume 1, and chap. 4 in vol II, those should help matter some what. Hope it helps David M. O'Rourke +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | dorourke@polyslo | Disclaimer: All opinions in this message are mine, but | | | if you like them they can be yours too. | | | Besides I'm just a student so what do I | | | know! | |-----------------------------------------------------------------------------| | When you have to place a disclaimer in your mail you know it's a sign | | that there are TOO many Lawyer's. | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++