Objective-C - Adding GPS information to a photograph - iphone

I am wondering if it is possible to add GPS information to a photograph when saving the item to the camera roll.
The code I currently use to save the image is:
UIImage *theImage = (UIImage *)[info objectForKey: UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(theImage, self,
#selector(image:didFinishSavingWithError:contextInfo:), nil);
I am wondering how I can modify the image EXIF data to add the current location, and make it compatible with the 'Places' functionality on the iPhone.

This example: http://caffeinatedcocoa.com/blog/?p=7 explains how to update the date of a photo. Go to CGImageProperties Reference and do the same replacing the key kCGImagePropertyExifDateTimeDigitized of the example with the relevant GPS keys. I haven't try this myself, but sounds like it should work. :)

Related

how to get iphone ipod playlist images and display it in image view

I am working with iphone ipod to read the album and playlist and play it in my application.
My question is that that i get the image from the album i have selected. and it is also working well in my application.
But i never get images from the playlist which i have selected their are different songs in my playlist and also having different image for that songs. for the album i have get the code and it work great. i am new for this and i cant found any reference code for this.
And i am using AVPlayer to play the songs.
So please help me and provide some sample code. for how to get all images from playlist and convert that image to data in iphone.
Please help me.
You're looking for is the MPMediaItemPropertyArtwork for MPMediaItem. As stated in the docs. After getting the artwork property you can make a MPMediaItemArtwork object, as stated in the docs.
An MPMediaItemArtwork object, or media item artwork, represents a graphical image, such as music album cover art, associated with a media item. Media items are described in MPMediaItem Class Reference.
With this you can do something like this. Assuming song is an MPMediaItem:
UIImage *image = nil;
MPMediaItemArtwork *itemArtwork = [song valueForProperty:
MPMediaItemPropertyArtwork];
if(itemArtwork != nil)
image = [itemArtwork imageWithSize:CGSizeMake(100,100)];
Now you have image containing your MPMediaItem artwork, set it to your image view ([myImageView setImage:image]). Keep in mind, this will only work if artwork IS available.
Hope this helps.
You can use VTM_AViPodReader demo for this.

Get actual file name when using writeImageToSavedPhotosAlbum for iOS

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);

AssetsLibrary: Location Services prompt. How did Instagram avoid it?

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];
}
}

Save a UIImage to a different name

I am writing an application which lets the user pick one photograph from a selection. Then I want to save that photograph to their photo roll to a specific name. i.e I always want the photo in the roll to be named the same thing and overwrite previous selections.
UIImage* image = [UIImage imageNamed:[ImageNames objectAtIndex:self.miImage]];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
I can't find anyway to make a copy of the image and assign a new name to it, or specify a target name for UIImageWriteToSavedPhotosAlbum().
Is there any way to do this?
thanks in advance,
Jay
You cannot specify a filename when using UIImageWriteToSavedPhotosAlbum because it saves the image to the Camera Roll (or the Photos Library, if the device does not have a camera). This allows the system to assign it a name based on a format, like "DSC0001.jpg" or similar, and avoid name collisions.
Because of this, overwriting an image is also not possible, since the Photo Library / Camera Roll are controlled by the user - a user that would not appreciate a photo being overwritten by your application.
...writing the image to the user’s Camera Roll or Saved Photos album.
UIImageWriteToSavedPhotosAlbum Reference

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???