Saving UIImage as PNG to photo album on iPhone - iphone

I am merging some png files to a uiimage and I followed this thread ( UIImageWriteToSavedPhotosAlbum save as PNG with transparency? )
and tried to save the result as a png file by replacing this code with my image: [self composeImageWithWidth:100 andHeight:100)..
When I test this using simulator, I go to the folder in application support and find the png there. However when I test this on a real device, I cannot find the png file in my photo album.
What could be going wrong?
Perhaps the paths of photo album?
Thanks for the answers

You can use this function:
UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
You only need completionTarget, completionSelector and contextInfo if you want to be notified when the image is done saving, otherwise you can pass in nil.
More info here

Related

Camera Roll asset images not available after saving an image to Saved Photos

I am using ALAssetsLibrary to make an array of all images in the camera roll when my iPhone app starts. I store every image as a ALAsset * in an array.
Later in the app, I am saving an image to the gallery using this:
UIImageWriteToSavedPhotosAlbum(croppedImage, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
The image is saved successfully to the saved photos album. But, now my problem is that when I try to retrieve images using the existing array of all images, I don't get anything. Do I need to build the array of all images again or is there some other way to do this?
Saving an image changes the library and invalidates objects like assets from the library. You need to reload assets from the library whenever the library changes - do that when you receive an ALAssetsLibraryChangedNotification.

Unable to convert a PNG image using UIImagePNGRepresentation

I'm writing a function to download a regular PNG file from web server and save it to iPhone Photos album. I don't get any error for my code listed below but UIImagePNGRepresentation doesn't perform the convert at all. All images I got were black. I have to enable "auto-enhanced" under Photos to display those image properly. Any clue what's wrong with my code? Thanks in advance.
UIImage *orgImg = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://server.com/test.png"]]];
NSData * convertedData = UIImagePNGRepresentation(orgImg);
UIImage * img = [UIImage imageWithData: convertedData];
// Save Image to Photo Album
UIImageWriteToSavedPhotosAlbum(img, self,
#selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:), nil);
Some more details of these two output images, orgImg and img:
If I pass orgImg to UIImageWriteToSavedPhotosAlbum directly, I did get the same PNG image hosted on the server. However Photos application on my iPhone displays it as a black image because Photos doesn't enhance PNG format automatically.
As for the img I got after using UIImagePNGRepresentation, the image data has been changed by the method, some meta data such as width/height have been removed from the original image. However Photos app on my iPhone still display it as an all black image.
Both images display properly if I copy them into either Safari or email. I didn't get any problem if I use JPEG in the server side either. Just curious why only PNG format doesn't work.

Create, Delete, and add pictures to albums in the photos app?

Haven't seen anything, but I have seen that you can create albums in the iOS 5 photos.app, and I was curious if there is a way to integrate it in my app.
I need to be able to create the album, upload pictures to it, and be able to delete it.
Thanks,
Coulton
Since iOS5 you can programmatically add albums to Photos. See the ALAssetsLibrary Class Reference.
You can add an album (which is an ALAssetsGroup) with:
addAssetsGroupAlbumWithName:resultBlock:failureBlock:
Every ALAssetsGroup has a URL associated with it. You'll want to save it:
valueForProperty:ALAssetsGroupPropertyURL
You can then use that URL to get an ALAssetsGroup object:
groupForURL:resultBlock:failureBlock:
Once you have your ALAssetsGroup you can use addAsset: method on it to add an image or video.
Notice: all these methods are asynchronous and return immediately. You do the actual work in the blocks you pass to these methods.
See the UIImage class reference:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html
void UIImageWriteToSavedPhotosAlbum (
UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo
);
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImageWriteToSavedPhotosAlbum
Adds to the camera roll album (camera) or saved photos album (no camera).

iPhone rewrite image file

I would like to access an image file in the iPhone images directory.
Then I would like to open this file as binary and be able to rewrite it.
Assuming user has chosen this file using the UIImagePickerController, is it possible to do such thing using iPhone API?
http://developer.apple.com/library/ios/#DOCUMENTATION/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/PickinganItemfromthePhotoLibrary.html this tutorial will help you in getting UIImage from photo library.
Once you obtain the image, you can do custom modifications to the UIImage and save it to photo album using this API:
Adds the specified image to the user’s Camera Roll album.
void UIImageWriteToSavedPhotosAlbum (
UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo
);
If you are looking to replace the existing photo from Photo library , there is no direct (or Apple Approved) way to do that. If you still want to do that, you can find path to photo library (/private/var/mobile/Media/DCIM/100APPLE) and try rewriting the photos.

Retrieving an iPhone photo saved to the photo library

I am saving images to the photo library and would like to retrieve them dynamically to display in future launches of my app. I use the WriteToSavedPhotosAlbum function, as below, but do not get any info to access the saved photo programmatically.
UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
Once saved, is there a way to retrieve the file name/id and load an image from the photo library at a later time?
You just need to save them for yourself.
Possibly in your app's documents or cache folder.
As a side note, when you say: "display at launch", if you mean to replace the Default.png, that won't work.
The launch image must be static and included in your app bundle.
If not, disregard.
You can't, unless the user picks the photo using the UIImagePickerController.
Check this related question
try this code segment make the necessay changes
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=pickerDelegate;
picker.sourcetype=UIImagepickerControllerSourceTypePhtoLibrary;