gpt4 book ai didi

cocoa - PicHandle 到 CGImageRef

转载 作者:行者123 更新时间:2023-12-03 17:44:22 32 4
gpt4 key购买 nike

该项目是一个具有核心图形支持的通用 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。请参阅 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);

关于cocoa - PicHandle 到 CGImageRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3856872/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com