@implementation NSImage (cgImage)

-(CGImageRef)cgImage{
	NSData* data = [self TIFFRepresentation];
    CGImageRef        imageRef = NULL;
    CGImageSourceRef  sourceRef;
    
    sourceRef = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
    if(sourceRef) {
        imageRef = CGImageSourceCreateImageAtIndex(sourceRef, 0, NULL);
        CFRelease(sourceRef);
    }
    return imageRef;
}

@end