-
- NSSize imageSize = [nsimage size];
- CGColorSpaceRef genericRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
- CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 0, genericRGB, kCGImageAlphaPremultipliedFirst);
- NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
- [NSGraphicsContext saveGraphicsState];
- [NSGraphicsContext setCurrentContext:nsGraphicsContext];
- [[NSColor whiteColor] setFill];
- NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height));
- [nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
- [NSGraphicsContext setCurrentContext:nsGraphicsContext];
- CGImageRef image = CGBitmapContextCreateImage(context);
- CFRelease(context);
+
+ CGImageRef image = NULL;
+ if (nsimage != nil)
+ {
+ NSSize imageSize = [nsimage size];
+ CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 0, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst);
+ NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:nsGraphicsContext];
+ [[NSColor whiteColor] setFill];
+ NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height));
+ [nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
+ [NSGraphicsContext setCurrentContext:nsGraphicsContext];
+ image = CGBitmapContextCreateImage(context);
+ CFRelease(context);
+ }