【问题标题】:PicHandle to CGImageRefPicHandle 到 CGImageRef
【发布时间】:2010-10-04 15:51:38
【问题描述】:

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


    【解决方案1】:

    在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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      相关资源
      最近更新 更多