Created
January 24, 2011 04:27
-
-
Save tgaul/792829 to your computer and use it in GitHub Desktop.
Generating a 1-bit GIF with ImageIO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) generate1BitGIF | |
{ | |
UIImage* image = [ UIImage imageNamed: @"TestImage.png" ]; | |
NSFileManager* fm = [ NSFileManager defaultManager ]; | |
NSURL* destDir = [ fm URLForDirectory: NSDocumentDirectory | |
inDomain: NSUserDomainMask | |
appropriateForURL: nil | |
create: YES | |
error: nil ]; | |
NSURL* destUrl = [ destDir URLByAppendingPathComponent: @"test.gif" ]; | |
CGImageDestinationRef dst = CGImageDestinationCreateWithURL( (CFURLRef) destUrl, kUTTypeGIF, 1, NULL ); | |
const uint8_t colorTable[ 6 ] = { 0, 0, 0, 255, 255, 255 }; | |
NSData* colorTableData = [ NSData dataWithBytes: colorTable length: 6 ]; | |
NSDictionary* gifProps = [ NSDictionary dictionaryWithObject: colorTableData | |
forKey: (NSString*) kCGImagePropertyGIFImageColorMap ]; | |
NSDictionary* imgProps = [ NSDictionary dictionaryWithObject: gifProps | |
forKey: (NSString*) kCGImagePropertyGIFDictionary ]; | |
CGImageDestinationAddImage( dst, image.CGImage, (CFDictionaryRef) imgProps ); | |
CGImageDestinationFinalize( dst ); | |
CFRelease( dst ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does this do? Tried using it, colorTable doesn't seem to do anything?