Cocoa CGImageRef的PicHandle 此项目是一个通用的C++插件,具有核心图形支持。我无法成功地将PicHandle转换为CGImageRef。从CFDataRef保存图像会导致图像损坏 if(pic) { Handle thePictureFileHandle; thePictureFileHandle = NewHandleClear(512); HandAndHand((Handle)pic,thePictureFileHandle); dataProvider= CGDataProviderCreateWithData(NULL,(void*)*thePictureFileHandle,GetHandleSize( (Handle)thePictureFileHandle ),NULL ); CFDataRef data = CGDataProviderCopyData(dataProvider); CGImageSourceRef source = CGImageSourceCreateWithDataProvider(dataProvider, NULL); if ( source ) { cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); } CGDataProviderRelease(dataProvider); CFRelease( source ); CFRelease( data ); }
在Cocoa CGImageRef的PicHandle 此项目是一个通用的C++插件,具有核心图形支持。我无法成功地将PicHandle转换为CGImageRef。从CFDataRef保存图像会导致图像损坏 if(pic) { Handle thePictureFileHandle; thePictureFileHandle = NewHandleClear(512); HandAndHand((Handle)pic,thePictureFileHandle); dataProvider= CGDataProviderCreateWithData(NULL,(void*)*thePictureFileHandle,GetHandleSize( (Handle)thePictureFileHandle ),NULL ); CFDataRef data = CGDataProviderCopyData(dataProvider); CGImageSourceRef source = CGImageSourceCreateWithDataProvider(dataProvider, NULL); if ( source ) { cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); } CGDataProviderRelease(dataProvider); CFRelease( source ); CFRelease( data ); },cocoa,core-graphics,cgimage,quickdraw,Cocoa,Core Graphics,Cgimage,Quickdraw,在CGImageSourceCreateImageAtIndex中,您需要传递字典,说明您的数据是PICT。 请参阅Apple文档。你需要像这样做 CFDictionaryRef myOptions = NULL; CFStringRef myKeys[1]; CFTypeRef myValues[1]; myKeys[0] = kCGImageSourceTypeIdentifierHint; myValues[0] = (CFTypeRef)kUTTypeP
CGImageSourceCreateImageAtIndex
中,您需要传递字典,说明您的数据是PICT
。
请参阅Apple文档。你需要像这样做
CFDictionaryRef myOptions = NULL;
CFStringRef myKeys[1];
CFTypeRef myValues[1];
myKeys[0] = kCGImageSourceTypeIdentifierHint;
myValues[0] = (CFTypeRef)kUTTypePICT;
myOptions = CFDictionaryCreate(NULL, (const void **) myKeys,
(const void **) myValues, 1,
&kCFTypeDictionaryKeyCallBacks,
& kCFTypeDictionaryValueCallBacks);
cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, myOptions);
CFRelease(myOptions);