diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index 291a549dc4..6ac6f6d2ed 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -46,6 +46,7 @@ OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage( const CGRect * inBounds, CGImageRef inImage) ; WX_NSImage WXDLLIMPEXP_CORE wxOSXCreateNSImageFromCGImage( CGImageRef image ); +CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSSImage( WX_NSImage nsimage ); #endif long UMAGetSystemVersion() ; diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index c9504907ee..4beb7a3685 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -313,6 +313,25 @@ WX_NSImage wxOSXCreateNSImageFromCGImage( CGImageRef image ) return( newImage ); } +CGImageRef wxOSXCreateCGImageFromNSSImage( WX_NSImage nsimage ) +{ + // based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html + + 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 yellowColor] 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); + return image; + } + // ---------------------------------------------------------------------------- // NSCursor Utils // ----------------------------------------------------------------------------