[futurebasic] CFMutableDictionary...(fixed)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2012 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Tue, 31 Jan 2012 08:28:32 -0500
local mode
local fn CGSaveImageFile( ctx as CGContextRef, url as CFURLRef, type as CFStringRef , isJPG as boolean, compression as float )
'~'1
dim as CGImageDestinationRef   imageDest
dim as CGImageRef              image
dim as Boolean                 success : success = _false
dim as CFMutableDictionaryRef  jpgOptions
 
long if isJPG
beginCCode
jpgOptions = CFDictionaryCreateMutable(nil, 0, &kCFTypeDictionaryKeyCallBacks,  &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(jpgOptions, kCGImageDestinationLossyCompressionQuality,[NSNumber numberWithFloat:compression]); // set the compression quality here
endC
 end if

// CGBitMapContext -> CGImages
image = fn CGBitmapContextCreateImage( ctx )
long if ( image )
// we have a CGImage; attempt to save it to file
imageDest = fn CGImageDestinationCreateWithURL( url, type, 1, 0 )
long if ( imageDest )
// CGImage + CGImageDestination -> file
long if isJpg
beginCCode
CGImageDestinationAddImage( imageDest, image, jpgOptions );
endC
xelse
CGImageDestinationAddImage( imageDest, image, 0 )
end if
success = fn CGImageDestinationFinalize( imageDest )
CGImageRelease( image )
if isJpg then CFRelease( jpgOptions )
end if

end if
end fn = success