]> git.saurik.com Git - wxWidgets.git/commitdiff
adding NSImage to CGImageRef conversion
authorStefan Csomor <csomor@advancedconcepts.ch>
Fri, 2 Oct 2009 17:51:16 +0000 (17:51 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Fri, 2 Oct 2009 17:51:16 +0000 (17:51 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62225 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/cocoa/private.h
src/osx/carbon/utilscocoa.mm

index 291a549dc43abbb3c32cf7592308a5c71822b7e9..6ac6f6d2edc84ed5bf53d39928de1f849e727ab4 100644 (file)
@@ -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() ;
index c9504907ee6545af3c67f9eb0a5ec233051530ae..4beb7a36856e7131f46040e8415c4e70cdb5aa59 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------