ios: cache images in the application folder - iphone

I am working on an Iphone application.
The idea of the application is to allow the user to download a picture and to save it on his phone. and he can later open it. (Normal caching system)
What I am doing now is I get the UIIamge from the server and then I save it on the phone using:
UIImageWriteToSavedPhotosAlbum
And then I use the imagePickerController to allow the user to load the image.
My question is:
Is there a way I can save the image in the application folder? The idea is that I don't want to allow the user to delete the image from outside the application(I have a "clear images" button). Is there a place I can cache the images other than the Photo library? maybe in the application bundle or folder?
Thank you

Use either of the following methods to save the UIImage into your app's document directory
[UIImageJPEGRepresentation(image, JPEG_COMPRESSION_QUALITY)
writeToFile:photoPath atomically:YES];
or
[UIImagePNGRepresentation(image) writeToFile:photoPath atomically:YES];

Related

How to save image in my device image library folder from my app document folder in iPhone?

I am receiving some image from web-service and store them into my app document folder. Now I have create an image library with my app name in iPhone device. Now. I want to show the images in this image library.
For saving the system image I am using this code -
[self.library1 addAssetURL:url toAlbum:#"My_App_Name" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
}
}];
but this is not work when I get the url of my document folder image. Help me out or gave any solution.
iOS5 includes new API in the AssetsLibrary framework, which afford you the chance to manage your app’s own photo album inside the user’s photo library.
I think it is easy peasy. Your app should create an UIImage and will just need to pass it to the below method along with the album name and a block to handle.
-(void)saveImage:(UIImage*)image
toAlbum:(NSString*)albumName
withCompletionBlock:(SaveImageCompletion)completionBlock;
You can see more details here

Is there any standard fileopen dialog in iphone programming?

I want to create application, that will process images(mostly - photographs from mobile camera).
So i need at first to provide the way to open image file from phone memory.
how can i do that?
Sorry for such a stupid question, but i am newbie in iphone programming(yet:)).
P.S. I use xcode, cocoa
You can use UIImagePickerController to get a standard interface for selecting a photo from the user's library or camera roll. Depending on the configuration, it can also be used to capture a new image with the camera. Note however that you get a UIImage back, not a file, if you want to upload it somewhere, you will first have to create a file or NSData object from the image, using either UIImagePNGRepresentation() or UIImageJPEGRepresentation().

iPhone application cannot load images from an album

I have developed a small iPhone application in which a user can choose images from an image picker and that image will appear in a View. When the user first selects an image I have saved the image name to a database and I save that image to a resource folder with that name. When the main view appears I search for images from the resource folder and display that image in the main view.
When I run this application in the iPhone Simulator it successfully runs, but when I actually tried it for testing purposes on my iPhone I am not able to display images in the main view. Anyone have an idea what's wrong with that?
Hi shivang,
I think you are saving the image to NSDocumentDirectory on a first click and trying to reload that.
while retriving the files from the NSDocumentDirectory you better
first check it for the file type like jpg,png,mp3 then give the
exact name to retrive that.
NSDocumentDirectory creates unique memory for every app and its
limited,check for the size of the images u r saving.
better try this code
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath:myfilepath error:nil])
{
if ( [fileName rangeOfString:#".jpg"].location != NSNotFound )
{
// Here fileName is used as a temporary variable to retrive image name
// myfilepath is the path where u stored the images
}
}

Is there a way to get paths of all the images of CAmera roll

Is there any way to create an array or something
having paths of all the images stored in camera roll.
Please enlighten me on this.
Thnx in advance
SpyPhone uses a direct path to the users photo library:
http://github.com/nst/spyphone/
It seems that any application can read it. However, this seems like falls under the area of "undocumented API" and could well be rejected in a real application.
I don't think there is. As far as the API is concerned for the UIImagePickerController you can only get a single path for a Movie that was recorded by the user (if running 3.0 on a 3GS). And even that path is a file URL to the temporary folder where the movie is stored before being written to the library.
You can't get paths for any images in the photo library or the camera roll.
When you pick an image using the UIImagePickerController the controller returns the Original Image and an "Edited Image" if the image was edited before being chosen.

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;