[comp.sys.mac.programmer] Loading Pict files

rjohnson@seas.gwu.edu (Ray Johnson) (11/14/90)

Does anyone have some sample code that loads a PICT and displays
it ( or at least just loads it ).  I've been pounding my head and
reading inside Mac but neither option has helped yet.  The part
I'm most confused on is how to know where to load the PICT from
in the file and what its Picframe is.

Any help is greatly welcome!!!

-- 
Ray Johnson
Internet: rjohnson@seas.gwu.edu       Phone: (202)994-6853
The George Washington University

mlab2@kuhub.cc.ukans.edu (11/15/90)

In article <2348@sparko.gwu.edu>, rjohnson@seas.gwu.edu (Ray Johnson) writes:
> Does anyone have some sample code that loads a PICT and displays
> it ( or at least just loads it ).  I've been pounding my head and
> reading inside Mac but neither option has helped yet.  The part
> I'm most confused on is how to know where to load the PICT from
> in the file and what its Picframe is.
> 
> Any help is greatly welcome!!!
> 
> -- 
> Ray Johnson

For starters:
The PICT should reside in your apps resource fork.  If you can get the PICT to
your scrapbook (say, Copy from MacPaint) then you merely open your programs
resource fork with ResEdit and Paste.  You should get a PICT type resource
appearing as a resource.  Make note of its ID number (Get Resource Info).

Your program will call up this PICT with GetPicture and DrawPicture it into the
active port.  Here's some Pascal code that should get you started.

procedure GetAPict;
  var
    savePort:WindowPtr;
    thePictsH:PicHandle;
    tempRect:Rect;

begin
  GetPort(savePort);
  SetPort(portToDrawTo);
  thePictsH := GetPicture(pictsID);
  if (thePictsH <> nil) then
    begin
      HLock(Handle(thePictsH));
      tempRect:=thePictsH^^.picFrame;
      HUnlock(Handle(thePictsH));
      OffsetRect(tempRect,horiOffset,vertOffset);
      DrawPicture(thePictsH, tempRect);
    end;
  ReleaseResource(Handle(thePictsH));
  SetPort(savePort);
end;

portToDrawTo is the window or offscreen port where you want the PICT to appear. 
pictsID is that ID number from the programs resource fork.
We lock the handle and get a copy of the PICTS frame.
horiOffset and vertOffset are two integers to move the rectangle where the PICT
will be drawn.  This is a simplified example.
Finally, we free up the memory by releasing it (no need to have TWO copies of
the PICT in memory after we have already drawn it where we want it.

Is that it?

john
:======:****************************************************************
: ==== :*                  **  And watching the stars go on at night, **
:  === :*   Soft Dorothy   **  I'd like to see just one of them die.. **
:  ==  :*                  *****************************************jc**
:.=....:****************************************************************