Can't get image from cacheDisplayInRect:toBitmapImageRep
Can't get image from cacheDisplayInRect:toBitmapImageRep
- Subject: Can't get image from cacheDisplayInRect:toBitmapImageRep
- From: Jørgen Tjernø <email@hidden>
- Date: Wed, 28 Jul 2010 16:32:20 -0700
Hi,
I'm trying to capture a part of my view for use in NSView's dragImage,
but cacheDisplayInRect:toBitmapImageRep: seems to capture a blank
image. My custom NSView doesn't draw opaquely, but the region I'm
trying to capture is drawn on - my view draws a checkerboard with
except for "spacing" between each cell which is left transparent. My
NSView is contained in a stock NSBox which is contained in a stock
NSWindow.
If I load an NSImage from a file and replace "image" in the drawImage
call with this, then it shows up fine, and while the docs for
cacheDisplayInRect says that it'll produce a 100% alpha image if the
requested rect is somewhere nothing is drawn, I'm requesting an area
within the bounds of the NSView (as the log output below shows).
This is what shows up in Console.app:
self frame, bounds: {{18, 14}, {508, 508}}, {{0, 0}, {508, 508}}
tileRect: {{306, 204}, {32, 32}}
NSBitmapImageRep: NSBitmapImageRep 0x100171e00 Size={32, 32}
ColorSpace=Color LCD colorspace BPS=8 BPP=32 Pixels=32x32 Alpha=YES
Planar=NO Format=0 CurrentBacking=<NSMutableData: 0x100161020>
NSImage: <NSImage 0x100173390 Size={32, 32} Reps=(
"NSBitmapImageRep 0x100171e00 Size={32, 32} ColorSpace=Color LCD
colorspace BPS=8 BPP=32 Pixels=32x32 Alpha=YES Planar=NO Format=0
CurrentBacking=<NSMutableData: 0x100161020>"
)>
And here is the code I use to produce the above input / attempt to
capture the display:
NSLog(@"self frame, bounds: %@, %@", NSStringFromRect([self
frame]), NSStringFromRect([self bounds]));
NSLog(@"tileRect: %@", NSStringFromRect(tileRect));
NSBitmapImageRep *imageRep = [self
bitmapImageRepForCachingDisplayInRect:tileRect];
[self cacheDisplayInRect:tileRect toBitmapImageRep:imageRep];
NSImage *image = [[[NSImage alloc] initWithSize:tileRect.size] autorelease];
[image addRepresentation:imageRep];
NSLog(@"NSBitmapImageRep: %@", imageRep);
NSLog(@"NSImage: %@", image);
NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType]
owner:self];
[pboard setString:@"Foo" forType:NSStringPboardType];
[self dragImage:image
at:tileRect.origin
offset:NSZeroSize
event:theEvent
pasteboard:pboard
source:self
slideBack:YES];
Any help or advice would be greatly appreciated!
Kind regards,
Jørgen.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden