这个项目是一个支持核心图形的通用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 );
}
答案 0 :(得分:2)
在CGImageSourceCreateImageAtIndex
中,您需要传递字典,说明您的数据是PICT
。
请参阅Apple文档here。你需要做一些像
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);