Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Encode animated GIF files on the iPhone
branch: master

This branch is 11 commits ahead, 9 commits behind unixpickle:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Classes
Giraffe.xcodeproj
Giraffe-Info.plist
GiraffeViewController.xib
Giraffe_Prefix.pch
MainWindow.xib
Matt.png
README
main.m
matt1.png
matt2.png

README

A simple GIF encoding class library for creating small animated GIF images.  This encoder does not use LZW compression, but instead uses uncompressed GIFs by insert clear codes as needed, and forcing bytes to be nine bits. Added a palette class to create palette from an image (single at this point), which will reduce itself to 255 colors (if necessary) using a median-cut algorithm.

Encode an animated gif of two partially transparent png images (matt1.png, matt2.png) as follows:

// create Palette first
UIImage *paletteImage = [UIImage imageNamed:@"Matt.png"];
ANPoint *mattePoint = [[ANPoint alloc] initWithR:255 withG:255 withB:255];
ANGifPalette *palette = [[ANGifPalette alloc] initWithImage:paletteImage.CGImage withMatte:mattePoint];

NSString *fileName = [NSString stringWithFormat:@"%@/Documents/matt_walk.gif", NSHomeDirectory()];
ANGifBitmap *bmp = [[ANGifBitmap alloc] initWithImage:[UIImage imageNamed:@"matt1.png"] withColorPalette:palette];
ANGifBitmap *bmp2 = [[ANGifBitmap alloc] initWithImage:[UIImage imageNamed:@"matt2.png"] withColorPalette:palette];
ANGifEncoder *enc = [[ANGifEncoder alloc] initWithFile:fileName withColorPalette:palette animated:YES];

// image creation
[enc beginFile:bmp.size delayTime:0.5f];
[enc addImage:bmp];
[enc addImage:bmp2];
[enc endFile];

// release objects	
[enc release];
[bmp release];
[bmp2 release];
[mattePoint release];
[palette release];
[fileName release];
Something went wrong with that request. Please try again.