Cocoa 如何从自定义视图(NSView)生成缩略图视图?

Cocoa 如何从自定义视图(NSView)生成缩略图视图?,cocoa,Cocoa,如何使缩略图视图(不是图像)形成自定义视图(NSView) 如果自定义NSView的内容更改,则缩略图视图将更改 看起来像是我的书的作者 谢谢大家 我建议你下次多做一些谷歌搜索,并告诉我们你尝试了什么,但我还是会回答: 您可能希望使用NSView的-(void)cacheDisplayInRect:toBitmapImageRep:创建包含缩略图的NSImage。以下是我在应用程序中使用的内容: - (NSImage *)snapshotForRect:(NSRect)destinationRe

如何使缩略图视图(不是图像)形成自定义视图(NSView)

如果自定义NSView的内容更改,则缩略图视图将更改

看起来像是我的书的作者

谢谢大家


我建议你下次多做一些谷歌搜索,并告诉我们你尝试了什么,但我还是会回答:

您可能希望使用
NSView
-(void)cacheDisplayInRect:toBitmapImageRep:
创建包含缩略图的
NSImage
。以下是我在应用程序中使用的内容:

- (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];
}
或者使用各种其他可用的方法


非常感谢。我尝试了这种方法,但遇到了性能问题。如果我从自定义视图生成图像。这样做太慢了。您是否分析过性能备份是否在您的绘图中,或者Cocoa如何调用您?你多久拍一次快照?非常感谢。我试图制作一个缩略图像,但是我们的图像速度太慢了。看看CareReplicatorLayer,创建这样一个“迷你地图”可能会有帮助。(感谢@Gralex)。