Getting details from photo - iphone

I'm working on an app that involves getting information from a photo that is taken with the in-built camera of the iPhone.
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
I would like to get the info on date/time of capture as well as the coordinates of the place of capture. Any idea how I would do this?

Using the Asset framework you can do this:
#import <AssetsLibrary/AssetsLibrary.h>
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
[library assetForURL:url resultBlock:^(ALAsset *asset) {
NSLog(#"TIMESTAMP: %#", [asset valueForProperty:ALAssetPropertyDate]);
} failureBlock:^(NSError *error) {
NSLog(#"FAIL");
}];

Related

Video streaming with ipCamera in iphone

I am developing app for the connecting ip camera and get stream. I don't know how to convert stream into video. I have analysed, and then i tried FFMPEG library. But i did not get correct url for ios with FFMPEG. Can you suggest the guide for implementation.
Now i am integrating ffmpeg, when i integrated i got the error when opening avformat_find_stream_info() function. I used the increase or less the value of pFormatCtx->max_analyze_duration. But no solution for this.
[mjpeg # 0x8b85000] max_analyze_duration 1000 reached at 40000
[mjpeg # 0x8b85000] Estimating duration from bitrate, this may be inaccurate
Pls help how to solve this.
Look at the "AVCam" example from Apple.
It does exactly that, and with lots of inline comments.
https://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html
Here is a small code snippet that will point you in the right direction:
Create an AVCaptureSession first...
// Init the device inputs
AVCaptureDeviceInput *newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:nil];
AVCaptureDeviceInput *newAudioInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self audioDevice] error:nil];
// Setup the still image file output
AVCaptureStillImageOutput *newStillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
AVVideoCodecJPEG, AVVideoCodecKey,
nil];
[newStillImageOutput setOutputSettings:outputSettings];
[outputSettings release];
// Create session (use default AVCaptureSessionPresetHigh)
AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];
Create the video file output
AVCaptureMovieFileOutput *aMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
if ([aSession canAddOutput:aMovieFileOutput])
[aSession addOutput:aMovieFileOutput];
Save the file:
-(void)recorder:(AVCamRecorder *)recorder recordingDidFinishToOutputFileURL:(NSURL *)outputFileURL error:(NSError *)error
{
if ([[self recorder] recordsAudio] && ![[self recorder] recordsVideo]) {
// If the file was created on a device that doesn't support video recording, it can't be saved to the assets
// library. Instead, save it in the app's Documents directory, whence it can be copied from the device via
// iTunes file sharing.
[self copyFileToDocuments:outputFileURL];
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
[[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
}
if ([[self delegate] respondsToSelector:#selector(captureManagerRecordingFinished:)]) {
[[self delegate] captureManagerRecordingFinished:self];
}
}
else {
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
if ([[self delegate] respondsToSelector:#selector(captureManager:didFailWithError:)]) {
[[self delegate] captureManager:self didFailWithError:error];
}
}
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
[[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]];
}
if ([[self delegate] respondsToSelector:#selector(captureManagerRecordingFinished:)]) {
[[self delegate] captureManagerRecordingFinished:self];
}
}];
[library release];
}
}

Is it possible to share an image via UIActivityViewController and retain exif data?

I have an app which saves images to a custom album within the camera roll via
[library writeImageToSavedPhotosAlbum:[newTestImage CGImage] metadata:metadata
completionBlock:^(NSURL *assetURL, NSError *error) {
//error
}
];
This works fine, however, I would then like to allow the user to share these images from within the app, I was doing it via
ALAsset *assetToShare = self.images[indexPath.row];
NSString *stringToShare = #"…..";
NSArray *dataToShare = #[assetToShare, stringToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion: ^{
//Some Expression
}];}
However in doing so the image is stripped of all exif data, is there a way I can implement the same functionality but retain the metadata? Thanks very much for any assistance.
Edit: Code used to enter ALAssets
if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:#"my pics"]) {
[self.assetGroups addObject:group];
_displayArray = [self.assetGroups objectAtIndex:0]; ...}];
Then:
[_displayArray enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
[self.images addObject:result]; }];
Have you tried something like this? Just passing the actual image.
ALAsset *assetToShare = self.images[indexPath.row];
ALAssetRepresentation *rep = [assetToShare defaultRepresentation];
UIImage *imageToShare = [UIImage imageWithCGImage:[rep fullResolutionImage]];
NSString *stringToShare = #"…..";
NSArray *dataToShare = #[imageToShare, stringToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:dataToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion: ^{
//Some Expression
}];}

Raw image data from camera

I've been searching this forum up and down but I couldn't find what I really need. I want to get raw image data from the camera. Up till now I tried to get the data out of the imageDataSampleBuffer from that method captureStillImageAsynchronouslyFromConnection:completionHandler: and to write it to an NSData object, but that didn't work.
Maybe I'm on the wrong track or maybe I'm just doing it wrong.
What I don't want is for the image to be compressed in any way.
The easy way is to use jpegStillImageNSDataRepresentation: from AVCaptureStillImageOutput, but like I said I don't want it to be compressed.
Thanks!
This is how i do it:
1: I first open the camera using:
- (void)openCamera
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
(NSString *) kUTTypeMovie, nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
}
else {
lblError.text = NSLocalizedStringFromTable(#"noCameraFound", #"Errors", #"");
}
}
When the picture is taken this method gets called:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Save and get the path of the image
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
// Save the image
image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if(!error) {
//Save path and location to database
NSString *pathLocation = [[NSString alloc] initWithFormat:#"%#", assetURL];
} else {
NSLog(#"CameraViewController: Error on saving image : %# {imagePickerController}", error);
}
}];
}
[imagePicker dismissModalViewControllerAnimated:YES];
}
Then with that path i get the picture from the library in FULL resolution (using the "1"):
-(void)preparePicture: (NSString *) filePathPicture{
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myasset)
{
if(myasset != nil){
ALAssetRepresentation *assetRep = [myasset defaultRepresentation];
CGImageRef imageRef = [assetRep fullResolutionImage];
if (imageRef) {
NSData *imageData = UIImageJPEGRepresentation([UIImage imageWithCGImage:imageRef], 1);
}
}else {
//error
}
};
ALAssetsLibraryAccessFailureBlock failureBlock = ^(NSError *error)
{
NSString *errorString = [NSString stringWithFormat:#"can't get image, %#",[error localizedDescription]];
NSLog(#"%#", errorString);
};
if(filePathPicture && [filePathPicture length])
{
NSURL *assetUrl = [NSURL URLWithString:filePathPicture];
ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:assetUrl
resultBlock:resultBlock
failureBlock:failureBlock];
}
}
Hope this helps you a bit further :-).

iPhone:import Video from iphone library

i am importing Video from iphone library In my app...but i am unable to do show i studied lots of code on stack over flow but none are working..for me..Basically i am doing sharing on fb and twitter...
..
-(IBAction)showVideoLibrary
{
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoPicker.mediaTypes =[[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie,nil];    
if(self.popoverController!=nil)
{
   [self.popoverController release];
}
self.popoverController  = [[UIPopoverController alloc] initWithContentViewController:videoPicker];
popoverController.delegate = self;
popoverController.popoverContentSize=CGSizeMake(320,1000);
[popoverController presentPopoverFromRect:CGRectMake(0,0,10,10) inView:self.view permittedArrowDirections:nil animated:YES];
}
thanks in advance
Try it on a real iPhone device.
Here is the code for picking video from iPhone library which i have used in my project.
Just add video method from selector to your desired button.
-(void)video
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
[self presentModalViewController:imagePicker animated:YES];
}
-(void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info
{
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo)
{
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL];
// NSLog(#"%#",moviePath);
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
}
}
[self dismissModalViewControllerAnimated:YES];
[picker release];
}
Do not forget to add mobile core services framework and to import
#import <MobileCoreServices/UTCoreTypes.h>
the string "moviepath" give you the path of the video in that iPhone then perform any desired thing with that video
You will get video path after compressing is done in string movie pathenter code here
MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url]; // give here the "videourl"
[[player view] setFrame: [self.view bounds]];
[self.view addSubview: [player view]];
[player play];

How to retrieve a video from the UISaveVideoAtPathToSavedPhotosAlbum

In my APP im saving the video to photolibrary using UISaveVideoAtPathToSavedPhotosAlbum. I am getting the path of the video but i am not able to play this video. Can any 1 help me with this on how to retrieve the saved video.Thanks in advance.I used the Code shown below.
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
} else {
picker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
UISaveVideoAtPathToSavedPhotosAlbum(tempFilePath, self, #selector(video:didFinishSavingWithError:contextInfo:), nil);
NSLog(#"temp path %#",tempFilePath);
[picker dismissModalViewControllerAnimated:YES];
}
NSURL *url = [NSURL fileURLWithPath:tempFilePath];
and Play the url using: "MPMoviePlayerController"
The path that is returned by this function needs a suffix. try this
NSString *videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSURL *videoURL = [NSURL URLWithString:[NSString stringWithFormat:#"file://localhost%#", videoPath]];