Allright, so with Peter's help I could figure this out. First, if you're working with image paths, then open directly the file with NSData like so:
NSData* imgData = [NSData dataWithContentsOfFile: filePath];
If you're working with NSImage objects and is difficult for you to have the path (for example with an NSImageView) then do this (image is the NSImage object you have):
NSData* imgData = [image TIFFRepresentation];
Now that you have your image into NSData objects, get it into a NSBitmapImageRep:
NSBitmapImageRep* bitmap = [NSBitmapImageRep imageRepWithData: imgData];
And then get a new NSData object, but with a different format:
NSData* newData = [bitmap representationUsingType: NSPNGFileType properties: nil];
// I used NSPNGFileType as an example, but all the
// types I wanted to convert between (except PDF) are supported
Finally, save that newData into a file:
[newData writeToFile: newPath atomically: YES]
Simple as pie, once you get how it works!
The support for transparency and size control is not that difficult either:
- The NSImage class provides support for setting image's size (-setSize:)
- The NSImageRep (superclass of NSBitmapImageRep) has the -setAlpha: method
Just call those when you need. +1 for Cocoa!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…