开发者

PicHandle to CGImageRef

开发者 https://www.devze.com 2023-01-18 12:36 出处:网络
This project is a generic C++ plugin with core-graphics support. I am unable to convert a PicHandle to CGImageRef successfully. Saving off image from CFDataRef results in a bad image.

This project is a generic C++ plugin with core-graphics support. I am unable to convert a PicHandle to CGImageRef successfully. Saving off image from CFDataRef results in a bad image.

    if(pic)
{
    Handle thePictureFileHandle;
    thePictureFileHandle = NewHandleClear(512); 
    HandAndHand((Handle)pic,thePictureFileHandle);

    dataProvider= CGDataProviderCreateWithData(NULL,(void*)*thePictureFileHandle,GetHandleSize( (Handle)thePictureFileHandle ),NULL );
    CFD开发者_运维问答ataRef data = CGDataProviderCopyData(dataProvider);
    CGImageSourceRef source = CGImageSourceCreateWithDataProvider(dataProvider, NULL);
    if ( source )
    {
        cgImageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);
    }
    CGDataProviderRelease(dataProvider);
    CFRelease( source );
    CFRelease( data );
}


In CGImageSourceCreateImageAtIndex, you need to pass the dictionary saying that your data is a PICT. See the Apple documentation here. You need to do something like

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

精彩评论

暂无评论...
验证码 换一张
取 消