views:

12

answers:

0

I'm trying to find a way to get an NSImage (or CGImage or CIImage, I'm not picky) containing only the visible rect portion of an NSTableView.

I've tried this:

NSRect visiblePart = [someTable visibleRect];
NSImage *tableImage = [[NSImage alloc] initWithSize:tableFrame.size];
[tableImage lockFocus];
[someTable drawRect:visiblePart];
[tableImage unlockFocus];

This gives me an image, but no matter where tableFrame's origin is set to, it is ignored, giving me an image of the correct size, but showing only the part that would be visible if I hadn't scrolled. So if the table looks like this:

xxxxxxx
xxxxxxx
xxxxxxx
yyyyyyy
zzzzzzz
zzzzzzz
zzzzzzz

If the initial portion visible is from the x rows to the y rows, then I scroll so that the only visible portion is from the y rows to the z rows, I get an image that is the size of y to z, but it contains an image of only the y row stuck at the bottom. In other words it draws the portion of the unscrolled visible area, but with the part that is no longer visible rendered transparent.

drawRect may not be the way to go, but I've tried a couple of other methods but haven't had success. I don't want to use dataWithPDFInsideRect, because it is too slow for what I'm doing.