Tutorial :Comprehensive Image processing example using Cocoa API


Can someone point out a comprehensive example on Image processing using cocoa API? I am developing an application for the Mac, and not for the iphone device. I usually come across with UIImage manipulation which provides an intuitive set of methods to achieve task such as per pixel manipulation and saving into file at different format. In the case with Appkit, NSImage I really find it hard to manipulate per pixel data of the images and saving to different file formats such as PNG not just TIFF.


If you want to work with pixels, CGImage and CGImageSource and CGImageDestination are the way to go. Unlike AppKit's NSImage, which is designed generally in order to handle any kind of image, the CGImage classes are specifically designed for raster images.


You can retrieve a bitmap representation of your image object and modify its data

NSBitmapImageRep *rep = [[image representations] objectAtIndex: 0];  unsigned char *bmpData = [rep bitmapData];  

To save modified representation in PNG format do the following:

NSData *data = [bits representationUsingType: NSPNGFileType properties: nil];  [data writeToFile: @"/path-to-your-file/image.png" atomically: NO];  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »