Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!ub!dsinc!netnews.upenn.edu!mscf.med.upenn.edu!peters_r From: peters_r@mscf.med.upenn.edu Newsgroups: comp.sys.mac.programmer Subject: Converting Pichandles to bitmaps Message-ID: <1991Jan24.020442.1@mscf.med.upenn.edu> Date: 24 Jan 91 02:04:42 GMT Sender: news@netnews.upenn.edu Organization: University of Pennsylvania, Med School Computer Facility Lines: 57 Recently, I ran into problems with slow drawing during my drag and Piupdate operations and decided to switch to copyBitting bitmaps instead of Drawpicturing pictures. To my surprise, I could find no evidence of a Toolbox routine to change pictures into bitmaps. So here is one I wrote: BitMap * PictureToBitMap( thePicture ) PicHandle thePicture; { GrafPtr tempPort = (GrafPtr) NewPtr(sizeof(GrafPort)); GrafPtr savePort; Rect r; int theID; BitMap map; GetPort( &savePort ); /* Create an off-screen grafport in which to draw the picture. */ OpenPort( tempPort ); /* Make sure that the structure, boundary, and size of the bitmap correspond to the picture we're going to draw. */ r = (**thePicture).picFrame; map.bounds = r; map.rowBytes = (((r.right - r.left) +15) /16) *2; map.baseAddr = NewPtr( map.rowBytes * (r.bottom - r.top +1)); SetPortBits( &map ); /* Make sure the port rectangle of our off-screen grafport is the same as the the picture frame. */ PortSize((r.right - r.left), (r.bottom - r.top)); SetPortBits( &map ); /* Drawing the picture will now alter our bitmap, and we'll capture the bit pattern we want. */ ClipRect( &tempPort->portRect ); EraseRect( &tempPort->portRect ); DrawPicture( thePicture, &r ); /* Clean up after ourselves. */ SetPort( savePort ); ClosePort( tempPort ); DisposPtr( tempPort ); /* Return home triumphant with the trophy. */ return ↦ } Please let me know if this works for you ( it works fine on a mac plus running system 6.0.5 (with old-style QuickDraw?)). Also let me know if in your references you find a more up-to-date Toolbox function which does this. l am also always on the lookout for ways to improve efficientcy. Thanks, Randy Peters