首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用alpha掩码创建自定义NSCursor?

如何使用alpha掩码创建自定义NSCursor?
EN

Stack Overflow用户
提问于 2019-09-07 00:20:24
回答 1查看 110关注 0票数 0

当我在Objective-C中创建一个自定义的NSCursor时,alpha通道掩码出现在下面的屏幕上。我期望一个0的alpha通道值是透明的,而不是XOR下面的图形。我确信我的掩码数据是正确的,其中A=0表示透明,A=255表示不透明。我做错了什么?

代码语言:javascript
复制
static void maincustomcursor(bigmap *thedata, point hotspot)
{
    NSPoint thepoint;
    NSImage *newimage;
    NSCursor *thecursor;
    CGImageRef theimage;
    CGBitmapInfo theinfo;
    CGContextRef thecont;
    CGColorSpaceRef thecolor;
    int width, height, across;

    width = (*thedata).width;
    height = (*thedata).height;
    if (width != smalliconsize || height != smalliconsize) return;
    if (hotspot.h < 0) hotspot.h = 0;
    if (hotspot.h >= smalliconsize) hotspot.h = smalliconsize - 1;
    if (hotspot.v < 0) hotspot.v = 0;
    if (hotspot.v >= smalliconsize) hotspot.v = smalliconsize - 1;
    thepoint = NSMakePoint(hotspot.h, hotspot.v);
    across = (*thedata).rowbytes;
    thecolor = CGColorSpaceCreateDeviceRGB();
    theinfo = (CGBitmapInfo)kCGImageAlphaPremultipliedFirst;
    thecont = CGBitmapContextCreate((*thedata).baseaddr, width, height, 8, across, thecolor, theinfo);
    theimage = CGBitmapContextCreateImage(thecont);
    newimage = [[NSImage alloc] initWithCGImage:theimage size:NSZeroSize];
    thecursor = [[NSCursor alloc] initWithImage:newimage hotSpot:thepoint];
    [thecursor set];
    [thecursor release];
    [newimage release];
    CGImageRelease(theimage);
    CGContextRelease(thecont);
    CGColorSpaceRelease(thecolor);
}
EN

回答 1

Stack Overflow用户

发布于 2019-09-08 03:14:24

好了,我想通了。当alpha通道=0时,需要确保红色、绿色和蓝色也为零。如果alpha通道是零,红色、绿色和蓝色是255,那么我看到的是像素的XOR。这可能与实现游标的古老方式有关,即清晰度、白色、黑色和异或依赖于位掩码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57825563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档