PDA

View Full Version : How to convert bitmap data to TIFF?




revg
Aug 21, 2008, 03:32 PM
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?


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



revg
Aug 21, 2008, 09:12 PM
Nevermind, I solved the problem!

Cheers,
Greg

lee1210
Aug 21, 2008, 09:20 PM
Nevermind, I solved the problem!

Cheers,
Greg

Care to share the solution in case others run into this/google it?

-Lee

revg
Aug 21, 2008, 11:08 PM
Here is the solution


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 );
}