Get actual file name when using writeImageToSavedPhotosAlbum for iOS - iphone

I'm writing an AR app that takes a screenshot and then places the image in the photo album so that the end user can get to it. I'm using writeImageToSavedPhotosAlbum. The major issue I'm having right now is that I can't seem to get the filename of the image.
I'm getting something like the following from NSURL:
assets-library://asset/asset.PNG?id=8AD512D0-205E-424D-B466-F31CCE4F299C&ext=PNG
When I need something like:
Image_0050.png
Does anyone know how to get the actual image name? Or, maybe I'm going about this entirely wrong?
Thanks,
Nathan

There is no name. All you have is a UIImage object.

The information you need is in ALAssetRepresentation of any ALAsset. All you need to do is get default representation of current asset and then you will have access to all information you want.
ALAsset *asset = <some_asset>;
NSLog(#"filename %#", asset.defaultRepresentation.filename);

Related

Sharing an image using parse.com

I would like to share an image between two users using parse.com. My original idea was to simple pass the image url from the first user to the second to view/download. I have no issue uploading the image to parse.com , however I can't work out how to return the url. Is it possible to return the url?
There seems to be a solution for this on android Get link to image file at Parse.com but I can't find one for iphone.
Thanks in advance
In the Image save example of Parse.com, I found the image url.
In - (void)setUpImages:(NSArray *)images method,
PFFile *theImage = [eachObject objectForKey:#"imageFile"]; will return image file object with its URL.
Hope this will help you.

Getting image name of iphone photo library

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.

Save iPhone Photo Library Path to a Plist

I want to save an image path string for a particular photo from the main iphone photo library in a plist file.
So that later I can call the plist image path string in a web view and see the photo.
I know I need the absolute path which is probably a similar path to the documents directory but:
1.) How do I get the photo name of the particular photo?
2.) Do I need to append the absolute path string to the photo name and then write to the plist?
3.) Will the path change for every install of my app - which would make a hard coded absolute path impossible to use?
Any pros want to tackle this conundrum?
If you are building an app targeting lower than iOS4.0, then you may use UIImagePickerController Class. This will let user pick one image from the phone album, which then, you can save in your app's documents directory and save the corresponding link in the info.plist file. The documents directory gets deleted when your app gets uninstalled, and so you lose the path as well.
A better way, with a disadvantage of restricting this feature (and so your app if its a main feature) to only iOS4.0 and above, would be using ALAssetsLibrary. Each photo in the iphone is represented by a unique URL that you can save, and you can refer to a particular image using that url. There is a nice tutorial blog that can help you get started with it.
Now, in your question, you are talking about a particular photo. You can not just know of any particular photo in the library, unless you let the user pick one. This brings me to answer your last question. The URL is constant for that particular image (till the iphone is reset), but unless you have any way of keeping that information between every install of your app (what exactly do mean here?), I don't know how being a unique URL is going to help you here.
EDIT:
Just saw the tag of sdk 4.0 there, please ignore the first case (the <4.0 part).
OK I think I want to use the UIImagePickerController!
Here is my code:
- (void)viewDidLoad {
self.iconPicker = [[UIImagePickerController alloc] init];
self.iconPicker.allowsEditing = YES;
self.iconPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
self.iconPicker.delegate = self;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
iconImage.image = [info objectForKey:UIImagePickerControllerEditedImage];
[picker dismissModalViewControllerAnimated:YES];
[picker release];
}
- (IBAction)save {
[plist.data setValue:iconImage.image forKey:#"Icon"];
[plist.data writeToFile:plist.file atomically:YES];
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
How do I save the image name of the edited image in plist string.
I know I don't want to save the CGImage data or whatever because of the load size.
I think I can pass an xcode variable into HTML through putting all my HTML into string objects and then adding variables to the objects where I need includes...
So I can create a path to the photo directory but I need to know how to get the name of the saved edited image from UIImagePickerController???

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;