NSBitmapImageRep should provide you with what you need. Load the data into NSBitmapImageRep and then use representationUsingType:properties: to get it as PNG. Quick example:
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:imageBuffer pixelsWide:imageWidth pixelsHigh:imageHeight bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bitmapFormat:NSAlphaFirstBitmapFormat bytesPerRow:imageWidth * 4 bitsPerPixel:32]; NSData *pngData = [imageRep representationUsingType:NSPNGFileType properties:propertyDictionary];
If you cannot use these Cocoa methods, check out libpng .
source share