2

How do I make a thumbnail view (It's not image) form a custom view(NSView)?

If the custom NSView's content changed that thumbnail view will be changed.

It's looks like ibook author.

Thanks all.

https://plus.google.com/u/0/photos/114755931805273493604/albums/5753531972174581009

CocoaUser
  • 1,361
  • 1
  • 15
  • 30

1 Answers1

2

I suggest you do some more Googling next time, and tell us what you have tried, but I'll answer anyways:

You may want to use NSView's -(void)cacheDisplayInRect:toBitmapImageRep: to create an NSImage which contains the thumbnail. The following is what I use in an app of mine:

- (NSImage *)snapshotForRect:(NSRect)destinationRect {
    NSView *view = ... // view you want thumbnail of
    NSBitmapImageRep *imageRep = [view bitmapImageRepForCachingDisplayInRect:destinationRect];
    [view cacheDisplayInRect:destinationRect toBitmapImageRep:imageRep];
    NSImage *renderedImage = [[NSImage alloc] initWithSize:[imageRep
                                                            size]];
    [renderedImage addRepresentation:imageRep];
    return [renderedImage autorelease];
}

Or use the variety of other methods available.

How do I take a "screenshot" of an NSView?

Google

Community
  • 1
  • 1
Vervious
  • 5,559
  • 3
  • 38
  • 57
  • Thanks so much. I tried this way, But I encountered performance issue. If I make an image from custom view. this way too slow. – CocoaUser Jun 14 '12 at 01:02
  • Have you profiled to see if the performance backup is in your drawing or in how Cocoa is calling you? How often are you taking the snapshot? – user1118321 Jun 14 '12 at 02:51