shanega@athena.mit.edu (Shane G. Artis) (05/23/91)
Hi. I am having some appkit programming difficulties. Does anyone have a good answer for this one? I am having a problem using a NXBitmapImageRep object to capture portions of an already drawn View. What I do is use a code fragment such as: tempbm = [[NXBitmapImageRep alloc] initData:tempdata fromRect:&aRect]; tempimage = [[NXImage alloc] initSize:&aRect.size]; [tempimage useRepresentation:tempbm]; to capture a rectangle from inside a window into a NXBitmapImageRep object, and hence to an NXImage object. Later in the code I redraw this image using: [tempimage composite:NX_COPY toPoint:&aPoint]; This procedure worked fine. Unfortunately, eventually I had the window that contained the View partially off-screen, and when I went to capture an image that was completely off-screen I got a message from the window server: Inconsistent set of values to create NXBitmapImageRep This was all that was printed, and when the code went to redraw the image no image was drawn. If the captured image is partially on-screen then the image appears to get redrawn to the wrong location. I need to study this a little more to find out the correlation between partially off-screen image capture and incorrect redrawing. Does anyone know of a reasonable solution to this problem? It doesn't seem to me that when using a Buffered window that NXBitmapImageRep should care whether I am drawing partially off-screen or not. Thanks, Shane
aozer@next.com (Ali Ozer) (05/28/91)
In article <1991May22.224125.25693@athena.mit.edu> Shane G. Artis writes: >I am having a problem using a NXBitmapImageRep object to capture portions >of an already drawn View. What I do is use a code fragment such as: > > tempbm = [[NXBitmapImageRep alloc] initData:tempdata fromRect:&aRect]; Presumably there is a lock/unlockfocus of the view somewhere around this statement... initData:fromRect: captures bits from the current focus. >This procedure worked fine. Unfortunately, eventually I had the >window that contained the View partially off-screen, and when I went >to capture an image that was completely off-screen I got a message >from the window server: > Inconsistent set of values to create NXBitmapImageRep Capturing bits from a buffered window should work whether or not the window is on or off screen. Of course, you have to make sure you are focused on the appropriate view and the actual backing window does exist (ie, is not deferred, which means it doesn't get created until made visible the first time, or one-shot, which means it's only visible when on-screen --- These are options you can set from Interface Builder; they help you in reducing startup time or window server memory usage...). You typically get the "Inconsistent set of values" error during initData:fromRect: if the rectangle you specified does not cover any pixels. This might indicate that the backing store of the window is not available or you're not properly focused on it (ie, you're focused on a part of the window not covered by the backing store). These are the most likely problems... Finally, a note about usage of NXBitmapImageRep and NXImage in your example: You use initData:fromRect: to read bits from a window into an instance of NXBitmapImageRep. This is fine and is the best way to read bits back from the window server. Then you give this instance of NXBitmapImageRep to an NXImage, who draws these bits in an off-screen window so you can composite elsewhere when you need to. It seems like you never actually use the bits; you bring them to the client side and send them back down to the server again. You might be able to get away without doing this round trip: Create an NXImage (using initSize:), lockFocus on it, and composite your view into it, using PScomposite(). Carrying bits back and forth between your app and the window server can be considerably slower than just compositing... Ali, Ali_Ozer@NeXT.com