使用子像素别名在图像中缓存 NSView
我想定期在 NSImage
中缓存 PDFView
的可见边界。稍后我会将图像绘制到屏幕上,因此我希望它看起来与原始 PDFView
完全相同。但是,在图像上下文中绘制 PDFView
的文本时,我无法让 Cocoa 使用子像素抗锯齿功能。它确实使用普通(即非 LCD)抗锯齿,但这会导致文本明显变浅。
有没有一种便携式方法可以解决这个问题?也就是说,当显示器支持子像素抗锯齿时,是否有办法在 NSImage
中缓存 NSView
?
我的代码:
PDFView *pdfView = ...
NSBitmapImageRep *rep = [pdfView bitmapImageRepForCachingDisplayInRect:[pdfView bounds]];
[pdfView cacheDisplayInRect:[pdfView bounds] toBitmapImageRep:rep];
NSImage *image = [[NSImage alloc] initWithSize:[rep size]];
[image addRepresentation:rep];
I want to periodically cache the visible bounds of a PDFView
in an NSImage
. I will later draw the image to the screen, so I'd like it to look exactly the same as the original PDFView
. However, I can't get Cocoa to use subpixel anti-aliasing when drawing the text of the PDFView
in the image context. It does use plain (i.e., non-LCD) anti-aliasing, but that results in noticeably lighter text.
Is there a portable way to fix this? That is, is there a way cache an NSView
in an NSImage
using subpixel anti-aliasing when the monitor supports it?
My code:
PDFView *pdfView = ...
NSBitmapImageRep *rep = [pdfView bitmapImageRepForCachingDisplayInRect:[pdfView bounds]];
[pdfView cacheDisplayInRect:[pdfView bounds] toBitmapImageRep:rep];
NSImage *image = [[NSImage alloc] initWithSize:[rep size]];
[image addRepresentation:rep];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论