I want to support get *.tiff data from clipboard, and convert it to bmp format. Below is my code, but it will crash in GetGraphicsImporterForDataRef. Could you please help? Many thanks for your help.

NSPasteboard* pPasteboard = [NSPasteboard generalPasteboard];
[pPasteboard retain];

ComponentInstance gi = 0;

NSData* data = [pPasteboard dataForType: NSTIFFPboardType];
Handle hPict = NewHandle([data length]);
HLock(hPict);
memcpy(*hPict, [data bytes], [data length]);
HUnlock(hPict);

//Crash here. Anything was wrong?
if(GetGraphicsImporterForDataRef(hPict, HandleDataHandlerSubType, &gi) != noErr)
   return;

long unsigned int imageCount = 0;
if(GraphicsImportGetImageCount(gi, &imageCount) != noErr)
  return result;

GraphicsImportSetImageIndex(gi, 0);

PicHandle hPicH;
GraphicsImportGetAsPicture(gi, &hPicH);

DisposeHandle(hPict);
CloseComponent(gi);
[pPasteboard release];

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to