Rap*_*ert 17 macos cocoa cursor nscursor
在OSX中,用户可以使用辅助功能系统首选项缩放鼠标光标.由于Lion(我认为)OSX将游标存储为PDF并且能够平滑地调整它们的大小.我希望我的应用程序具有相同的功能,但使用PDF作为NSImage我的用途NSCursor只是在设置了大于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];
Run Code Online (Sandbox Code Playgroud)
因此,本质上,这是基于原始PDF在图像中的适当比例因子下生成多个图像表示的。这对我有用,我的光标很流畅。
| 归档时间: |
|
| 查看次数: |
1319 次 |
| 最近记录: |