cocoa - PicHandle 到 CGImageRef

标签 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 );
}

最佳答案

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/

相关文章:

objective-c - 要子类化什么类 - NSView 或 NSButton

ios - 使用 Drawrect 绘图

ios - ARGB 图像的 CGContext.init 返回 nil

cocoa - NSButton + & - 按钮

cocoa - NSLevelIndicator 上有文字吗?

c# - 使用 C# 和 Xamarin 防止按 F8(播放)按钮后启动 iTunes/Music.app

ios - 如何让 UILabel 显示轮廓文本?

iphone - 更改 UIImage 的像素颜色值

ios - CGImageCreateWithMaskingColors 删除颜色时离开边框

ios - CoreImage CICrop 返回 0x0 像素图像