Saving UIImage to the photo album.

The simplest way to save a UIImage to the photo album is with the UIImageWriteToSavedPhotosAlbum() function. The simplest way is by specifying the UIImage, and none of the other parameters:

    UIImageWriteToSavedPhotosAlbum(image, nil,nil, nil);

However, this will save the image as a jpg, which is not always ideal. If you want to save it as PNG, you have to first encode the image as a PNG, then make a new image based on that PNG so that the PNG data is attached to it, and then save the new image:

    NSData *data=UIImagePNGRepresentation(image);
    image=[UIImage imageWithData:data];
    UIImageWriteToSavedPhotosAlbum(image, nil,nil, nil);

You can also force JPEG format (with your own compression quality) by doing the same thing, but with the UIImageJPEGRepresentation() call:

    NSData *data=UIImageJPEGRepresentation(image,1.0); // best quality
    image=[UIImage imageWithData:data];
    UIImageWriteToSavedPhotosAlbum(image, nil,nil, nil);