How to convert bitmap data to TIFF?

Discussion in 'Mac Programming' started by revg, Aug 21, 2008.

  1. revg macrumors newbie

    Joined:
    Aug 14, 2008
    #1
    Hi,

    I am using Carbon for my lanaguage and I am unable to use Cocoa. Does anyone know how I can convert the bitmap data returned as shown below to a TIFF format in a CFDataRef variable?

    Code:
    void *data = CGBitmapContextGetData (cgctx);
    //how can I now take the bitmap data from the variable data
    //and convert it to a CFDataRef in a TIFF format?
    
    Thanks
     
  2. revg thread starter macrumors newbie

    Joined:
    Aug 14, 2008
    #2
    Nevermind, I solved the problem!

    Cheers,
    Greg
     
  3. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #3
    Care to share the solution in case others run into this/google it?

    -Lee
     
  4. revg thread starter macrumors newbie

    Joined:
    Aug 14, 2008
    #4
    Here is the solution

    Code:
    void copyCGImageRefToPasteboard(CGImageRef ref)
    {
    	OSStatus err = noErr; 
    	PasteboardRef theClipboard; 
    		
    	err = PasteboardCreate( kPasteboardClipboard, &theClipboard ); 
    	err = PasteboardClear( theClipboard );// 1 
    		
    	CFMutableDataRef url = CFDataCreateMutable(kCFAllocatorDefault, 0);
    		
    	CFStringRef type = kUTTypeTIFF;
    	size_t count = 1; 
    	CFDictionaryRef options = NULL;
    	CGImageDestinationRef dest = CGImageDestinationCreateWithData(url, type, count, options);
    	CGImageDestinationAddImage(dest, ref, NULL);
    	CGImageDestinationFinalize(dest);
    
    	err = PasteboardPutItemFlavor( theClipboard, (PasteboardItemID)1, type, url, 0 ); 
    }
    
    
     

Share This Page