PicHandle到CGImageRef

时间:2010-10-04 15:51:38

标签: cocoa core-graphics cgimage quickdraw

这个项目是一个支持核心图形的通用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 );
}

1 个答案:

答案 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);