Вопрос

Этот проект представляет собой универсальный плагин C ++ с поддержкой основной графики. Я не могу успешно преобразовать пичу в 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 здесь. Отказ Вам нужно сделать что-то вроде

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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top