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;
Related
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];
I seem to be having caching issues with the ALAssetLibrary when testing my app on the iPhone.
Steps used to produce this issue
Take a photo using the iPhone camera
Access the Camera Roll using ALAssetsLibrary (through ELCImagePicker)
The problem is that when ELCImagePicker displays the list of albums, the thumbnail of the photo taken in step 1 is displayed for the Camera Roll album (which is correct), but when I go into the Camera Roll album, that photo is not there. An error like this is also displayed in the console log:
Cached count is off for 0x2391d0 <x-coredata://D226A7C3-95D5-40B3-BCFB-726E534AB57A/Album/p1> (1357 != 1358) moc=<PLManagedObjectContext: 0x63794c0>
1357 and 1358 appears to be match the photo count before and after I take the photo, and closing the image picker and opening it again doesn't help. But if I switch to the Photos app, the photo is displayed there. And when I return to my app, the photo is now displayed as well.
I have tried both
UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo );
and ALAssetsLibrary's
(void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef orientation:(ALAssetOrientation)orientation completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock
but neither works. Any help is greatly appreciated. Thanks!
You can listen for ALAssetsLibraryChangedNotification notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(reloadAlbumGroups) name:ALAssetsLibraryChangedNotification object:nil];
In reloadAlubmGroups load your album groups from assets library to get updated objects.
Apple Documentation:
ALAssetsLibraryChangedNotification
Sent when the contents of the assets library have changed from under the app that is using the data.
When you receive this notification, you should discard any cached information and query the assets library again. You should consider invalid any ALAsset, ALAssetsGroup, or ALAssetRepresentation objects you are referencing after finishing processing the notification.
In iOS v4.0, the notification’s object is nil. In iOS v4.1 and later, the notification object is the library object that posted the notification.
I'm doing a project to take images from iphone photo library or in other way from camera roll. I have done that without any problem. But i need to retrieve the name from the photo library. Is there a way to do that? Any help is appreciated
Thanks
Have a look at ALAssetsLibrary which is available in iOS 4.0 and later.
Also, these links may help
How to get a photo's original filename in iOS?
iPhone: How do I get the file path of an image saved with UIImageWriteToSavedPhotosAlbum()?
If you need the full path, just use this:
ALAsset* asset; // previously assigned
NSDictionary* pathInfo = [asset valueForProperty:ALAssetPropertyURLs];
This will leave the full URL of the image on your device as the Value member of the pathInfo object.
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).
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.