PicHandle a CGImageRef
-
27-09-2019 - |
Domanda
Questo progetto è un C ++ generica plugin con il supporto di base grafica. Non sono in grado di convertire un PicHandle a CGImageRef successo. Salvataggio fuori immagine da CFDataRef si traduce in una cattiva immagine.
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 );
}
Soluzione
In CGImageSourceCreateImageAtIndex
, è necessario passare il dizionario dice che i dati sono un PICT
.
Vedere la documentazione di Apple qui . Hai bisogno di fare qualcosa di simile
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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow