PicHandle到CGImageRef
-
27-09-2019 - |
题
此项目是一个通用的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 );
}
解决方案
在CGImageSourceCreateImageAtIndex
,你需要把字典说,你的数据是PICT
。
看到苹果文档这里rel="nofollow">。你需要做的是这样
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);
不隶属于 StackOverflow