How do I make a thumbnail view form custom view(NSView)?

前端 未结 1 1260
说谎
说谎 2021-01-16 03:41

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\

1条回答
  •  北恋
    北恋 (楼主)
    2021-01-16 04:00

    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

    0 讨论(0)
提交回复
热议问题