handling nil images correctly, solves #12956
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66979 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -409,18 +409,22 @@ CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage )
|
|||||||
{
|
{
|
||||||
// based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html
|
// based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html
|
||||||
|
|
||||||
NSSize imageSize = [nsimage size];
|
CGImageRef image = NULL;
|
||||||
CGColorSpaceRef genericRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
if (nsimage != nil)
|
||||||
CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 0, genericRGB, kCGImageAlphaPremultipliedFirst);
|
{
|
||||||
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
|
NSSize imageSize = [nsimage size];
|
||||||
[NSGraphicsContext saveGraphicsState];
|
CGColorSpaceRef genericRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
||||||
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 0, genericRGB, kCGImageAlphaPremultipliedFirst);
|
||||||
[[NSColor whiteColor] setFill];
|
NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
|
||||||
NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height));
|
[NSGraphicsContext saveGraphicsState];
|
||||||
[nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
|
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
||||||
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
[[NSColor whiteColor] setFill];
|
||||||
CGImageRef image = CGBitmapContextCreateImage(context);
|
NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height));
|
||||||
CFRelease(context);
|
[nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
|
||||||
|
[NSGraphicsContext setCurrentContext:nsGraphicsContext];
|
||||||
|
image = CGBitmapContextCreateImage(context);
|
||||||
|
CFRelease(context);
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user