nscursor - 如何创建带有 alpha 掩码的自定义 NSCursor?
问题描述
NSCursor
当我在alpha 通道中创建自定义时,Objective-C
蒙版出现XOR
在下面的屏幕上。我期望 alpha 通道值为零是透明的,而不是XOR
下面的图形。我确定我的掩码数据在透明和不透明的ARGB
地方是正确的。我究竟做错了什么?A=0
A=255
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);
}
解决方案
好的,我想通了。当 alpha 通道 = 0 时,您需要确保红色、绿色和蓝色也为零。如果 alpha 通道为零并且红色、绿色和蓝色为 255,那么我看到的是像素的异或。这可能与实现游标的古老方式有关,根据位掩码使用 clear、white、black 和 xor。
推荐阅读
- python - 如何根据另一列统计DataFrame中某个值出现的次数?
- arduino - 如何通过 5*5 按钮控制 5*5 Led 中的 Led - 矩阵
- javascript - 未应用 JQuery .hide 和 .show
- java - Intellij 中的 Google OR-Tools:UnsatisfiedLinkError
- swift - Swift 5.1 - Mac OS - 文件读取在操场上工作,但在应用程序中不工作
- vbscript - 从 UFT 中的命令提示符读取文本
- javascript - 使用 Flask 填充 Selectize.js 下拉列表
- python - 对 Pandas 数据框中的特定列进行排序
- android - 无需控制台即可在客户端访问 firebase/google 分析数据
- angular - 如何在http get request angular 8中将null更改为空值