Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!agate!shelby!polya!ali From: ali@polya.Stanford.EDU (Ali T. Ozer) Newsgroups: comp.sys.next Subject: Re: Bitmaps from views Message-ID: <12871@polya.Stanford.EDU> Date: 22 Nov 89 07:13:45 GMT References: <865@shelby.Stanford.EDU> Reply-To: ali@Polya.Stanford.EDU (Ali T. Ozer) Organization: . Lines: 64 In article <865@shelby.Stanford.EDU> Dave Combs writes: >I'm trying to speed up an interactive application by taking various >View-subclass objects and converting them to Bitmaps, which I can then >composite onto a window as I wish. Can someone explain to me how this is >done? One way to do it is to create a bitmap of the appropriate size, lockfocus on it, and do your drawing. I assume you currently have a drawSelf:: method which draws whatever your view is showing. To cache the image in a bitmap without having to change too much code in your subclass of View, you'd do something along the lines of... - drawSelf:(NXRect *)rects :(int)rectCount { if (needsCaching) { [cache lockFocus]; ... do your drawing ... [cache unlockFocus]; needsCaching = NO; } if (rectCount == 3) { // Scrolling diagonally; use last two rects [cache composite:NX_COPY fromRect:rects+1 toPoint:&(rects+1)->origin]; [cache composite:NX_COPY fromRect:rects+2 toPoint:&(rects+2)->origin]; } else { // Just use first rectangle [cache composite:NX_COPY toPoint:&rects->origin]; } return self; } Above we're assuming that you have a bitmap (named cache) which is the same size as the view. The variable needsCaching specifies whether the image needs to be cached in the bitmap or not. After we cache (if we need to), we go ahead and do the actual drawing through compositing. If you want to print, the above will cause the bitmap to dump its contents out to the printer; the compositing will be simulated through imaging. However, the image will be screen-res. If you want to get beautiful (300 or 400dpi) image out of the printer, you then need to make sure you check the value of NXDrawingStatus and if the value is NX_PRINTING simply execute the PostScript with the focus on the view itself. >I've tried using "copyPSCodeInside:to:" to put the View data onto a stream >(which is in EPS format, and works fine). I've then tried to use the >Bitmap function "newFromStream:" to read the data into a bitmap. However, >this always chokes (quietly) on the second byte read in, and gives me >nothing. Bitmap's newFromStream: method tries to read TIFF data from the stream, not PostScript. If you wish to create an image in a bitmap from PostScript, you need to simply lockfocus on the bitmap and execute the code... Several of the examples from /NextDeveloper/Examples use bitmaps to speed drawing up; for instance, BreakApp creates images of tiles & such in bitmaps and then composites them in; Draw uses caching to create images of the graphic objects in bitmaps so you can move them around quickly; and Yap uses code similar to what's above (see YapOutput.m) to create its image in a cache and scroll around in it. Ali