ivanceras
ivanceras

Reputation: 1455

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.

Upvotes: 1

Views: 1015

Answers (2)

Peter Hosey
Peter Hosey

Reputation: 96323

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.

Upvotes: 4

Michael
Michael

Reputation: 54705

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];

Upvotes: 0

Related Questions