Pichandle إلى Cgimageref
-
27-09-2019 - |
سؤال
هذا المشروع هو مكون إضافي عام C ++ مع دعم Graphics الأساسية. أنا غير قادر على تحويل 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 هنا. تحتاج إلى فعل شيء مثل
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);
لا تنتمي إلى StackOverflow