NSCursor: Using high-resolution cursors with cursor zoom (or retina)

微笑、不失礼 提交于 2019-12-03 05:55:46

I just got the solution told to me by @kongtomorrow. Here's the snippet he sent me:

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];

So essentially what this does is generate several image representations at the appropriate scale factors in the image, based on the original PDF. This works for me, my cursor is nice and smooth.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!