在 OSX 中,用户可以使用辅助功能系统首选项来缩放鼠标光标。因为 Lion(我认为)OSX 将光标存储为 PDF,并且能够平滑地调整它们的大小。我希望我的应用程序具有相同的功能,但使用 PDF 作为用于我的 NSCursor
的 NSImage
,当设置的光标缩放级别大于 1.0 时,只会放大渲染的位图。
我该怎么办:
- 为我的光标使用矢量图形并让它们像系统光标一样正确缩放?
- 检测当前光标缩放级别。
- 当光标缩放级别发生变化时收到通知?
此外,当我的屏幕使用 HiDPI 模式并恢复光标缩放设置时,PDF 光标也会变得模糊,那么你们到底是如何视网膜化光标的呢?
最佳答案
我刚刚收到@kongtomorrow 告诉我的解决方案。这是他发给我的片段:
NSImage * theImage = [NSImage imageNamed: @"CURS_128.pdf"];
NSImage *resultImage = [[NSImage alloc] initWithSize:[theImage size]];
for (int scale = 1; scale <= 4; scale++) {
NSAffineTransform *xform = [[NSAffineTransform alloc] init];
[xform scaleBy:scale];
id hints = @{ NSImageHintCTM: xform };
CGImageRef rasterCGImage = [theImage CGImageForProposedRect:NULL context:nil hints:hints];
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithCGImage:rasterCGImage];
[rep setSize:[theImage size]];
[resultImage addRepresentation:rep];
}
NSCursor* theCursor = [[NSCursor alloc] initWithImage: resultImage hotSpot: NSMakePoint(12,8)];
[self.scrollView setDocumentCursor: theCursor];
本质上,它的作用是根据原始 PDF 以图像中适当的比例因子生成多个图像表示。这对我有用,我的光标非常流畅。
关于macos - NSCursor:使用带有光标缩放(或视网膜)的高分辨率光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19245387/