I'm not quite new but still have a few noob questions this is one of them.
I need a path to one of the pictures all ready in my camera roll on my test iphone. How do I get/find this, not programmatically. I want to hard code it for testing for file upload so I can trouble shoot.
so
filePath:#"/private/var/mobile/Applications/14C39895-E73B-400F-8158-F1F5047A826C/tmp/upload.jpg"
should be what:
filePath:#"fill in this spot"
You can't access the photos directly (unless your app wrote them to the docs folder to begin with -- in which case you would know the path). You'll need to implement a UIImagePicker to select the photo from your photo album. The UIImagePicker delegate will then have access to the photo where you can do whatever you want with it(including writing a copy of it to documents). After the photos been selected once and written to docs, you could then access it in documents on later executions of the app.
The UIImagePicker delegate should implement:
-(void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *) info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
Then you can write the image to your apps docs folder in that delegate method, something like this:
http://blog.objectgraph.com/index.php/2010/04/05/download-an-image-and-save-it-as-png-or-jpeg-in-iphone-sdk/
At that point you could always access the photo in your apps docs folder for upload testing... You probably need to implement a UIImagePicker for your app anyway, so instead of looking for your test photo, it may be easier to just select from photo album using UIImagePicker and upload directly (cutting out the whole writing/reading from docs folder).
Hope that helps!
Related
I am working an app that uses the photos and videos in the AssetsLibrary, and I am just trying to determine once and for all if there is any way around asking the user for permission to access Location data in order to get these assets. I understand that the EXIF data includes GPS information, and that makes enough sense to me.
Note: I have searched through StackOverflow and I have found similar questions, and I am not making this post simply to add one more to the list. I am asking specifically about one (apparent) counterexample.
When using Instagram for the first time, I am able to browse through my photo album, select photos, edit them and share them all without ever being prompted about location services. I am only prompted when I choose to click on the button labeled "Enable Geotagging." Checking the settings tab, it looks like if I don't ever click that button, Instagram doesn't even come up in the Location Services section of my Settings.
My question is, how did Instagram get away with this? Anyone have any ideas? I'd like to figure out if I can mimic their implementation somehow so my users aren't shut out from getting their camera assets if they say no to this prompt.
the explanation is quite simple. Instagram uses the UIImagePickerController. UIImagePickerController works without Location Services enabled, but you don't get EXIF data using this method.
UIImagePickerController can retrieve metadata (incl. GPS) only through the UIImagePickerControllerReferenceURL. UIImagePickerControllerReferenceURL you have to pass then AssetsLibrary methods, which needs again location services enabled.
Cheers,
Hendrik
As holtmann mentioned, reading the UIImagePickerControllerReferenceURL triggers the location services prompt. If you only need the image data, not the metadata, you can get that from the UIImagePickerControllerOriginalImage and UIImagePickerControllerEditedImage keys instead (I'm checking EditedImage first and then checking OriginalImage if EditedImage is null). This doesn't require the use of the assets library and doesn't require location access.
Here's how I'm using this in my app, including saving a local copy of the image for further editing:
- (void)imagePickerController:(UIImagePickerController *)controller didFinishPickingMediaWithInfo:(NSDictionary *)info {
// get the selected photo as a UIImage
UIImage *photo = [info objectForKey:#"UIImagePickerControllerEditedImage"];
if (!photo) {
photo = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
// save the photo to the app's Documents folder
if (photo) {
NSString *extension = #"jpg";
NSString *filename = [NSString stringWithFormat:#"%#.%#", self.defaultTitle, extension]; // self.defaultTitle is defined elsewhere in my app
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"] stringByAppendingPathComponent:filename];
[UIImageJPEGRepresentation(photo, 0.8) writeToFile:path atomically:YES];
}
}
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().
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 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.
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;