0

When I create a custom NSCursor in Objective-C the alpha channel mask appears to XOR the screen below. I am expecting an alpha channel value of zero to be transparent, not XOR the graphics below. I am certain my mask data is correct ARGB where A=0 for transparent and A=255 for opaque. What am I doing wrong?

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); } 

1 Answer 1

0

OK I figured this out. When the alpha channel = 0 you need to be sure that red, green, and blue are also zero. If the alpha channel is zero and red, green, and blue are 255, then I am seeing XOR for the pixel. This may be related to the ancient way that cursors were implemented, with clear, white, black, and xor depending on the bit masks.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.