[iPhone SDK] Tips of UIImage and CGImage
Some greate UIImage, CGImage APIs are provided to manage and use image.
How to Expand UIImage for variable width buttons
It looks too bad, that an image is expanded directly when it is set to UIBotton, UIImageView and so on.
If you make it look so good, you don't have to directly expand image. If you use following API, when you scale or resize image, 4 corner area that you specify are are not scaled or resized. 2 arguments are corner areas' width and height.
UIImage *stretched = [original stretchableImageWithLeftCapWidth:5 topCapHeight:5];
Resize UIImage
Use this API, very simply. But this method is private and undocumented, you can't use this method for application to submit AppStore.
UIImage *resized = [image _imageScaledToSize:CGSizeMake( new_width, new_height ) interpolationQuality:quality];
Crop CGImage
You can crop the image with following API.
CGImageRef clipped = CGImageCreateWithImageInRect ( image, rectROI );
This API makes subimage from original CGImage. This API retains original image, doesn't alloc new CGImage.