I have a very simple bit of code that should capture a bitmap of a view. It was used to work at Leopard, but seems terribly overwhelmed at Snow Leopard.
Here is the code that presses the button on the button:
- (IBAction)snapshot:(id)sender { NSView* view = [[sender window] contentView]; NSBitmapImageRep* bitmap = [view bitmapImageRepForCachingDisplayInRect:[view bounds]]; NSData *tiff = [bitmap TIFFRepresentation]; [tiff writeToFile:[@"~/Desktop/snapshot.tiff" stringByExpandingTildeInPath] atomically:YES]; }
Pressing the button to create a snapshot results in a fully transparent image.
Am I just completely incomprehensible here, or is this method of bitmap caching broken?
A simple project - basically an NSDocument starter project with a button that calls this code - can be found here .
source share