UIImagePickerController Pick Multiple images - iphone

I am trying to simply enable picking multiple images from photolibrary using the UIImagePickerController, I wish I can add a subview on bottom of the photo picker so it look something like this app does:
It there a simple way you can do it? My code currently only pops the images in a standard way but I only dismiss the controller when loaded 6 images
The important thing there is if anyway I can add a small view/toolbar to the photo picker view, like the example did, I then can do the rest
- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType{
//get all available source types
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
//if source type available and supported media type is not null
if ([UIImagePickerController isSourceTypeAvailable:sourceType
&& [mediaTypes count] > 0]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//picker.mediaTypes = mediaTypes; //allow videos
picker.delegate = self;
picker.sourceType = sourceType; //set source type to the given type
/** WANT TO ADD A CUSTOM VIEW IN THE PHOTO PICKER VIEW **/
[self presentViewController:picker animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error accessing media"
message:#"Device doesn't support that media type"
delegate:nil
cancelButtonTitle:#"Drat !"
otherButtonTitles: nil];
[alert show];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType]; //record media type
//if media type is image
if ([lastChosenMediaType isEqual:(NSString *) kUTTypeImage]) {
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage]; //load image
//save the image if is from camera shot
if (imageOrVideoSourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum (chosenImage, nil, nil , nil);
}
[images addObject:chosenImage]; //add to image list
imageNum++;
}
changeImageOrVideo = true;
if(imageNum >= 5){
[picker dismissViewControllerAnimated:YES completion:nil];
}
}

The main reason for using hacks like shifting the UIImagePickerController up and showing selected images underneath was because the asset library alternative would involve the user being asked for location access due to the information about where the photo was taken being available in the image metadata.
In iOS 6 the user is asked if they want to allow the app to access their photos (not location) and you get asked this question for both the asset library approach and the UIImagePickerController approach.
As such I think that hacks like the above are nearing the end of their usefulness. Here is a link to a library providing selection of multiple images using the Assets library there are others.

Related

iPhone how to pick a latest taken image with default UIImagePicker

I have an option to display a UIImagePicker and select an image from the user's camera roll within my app. THe issue that I'm running in is that the photos are sorted with the oldest on top. This makes it easy to pick images that have been taken months ago. I want the user to quickly select images that were taken a few minutes ago without having to scroll to the end of the list (bottom of the list).
Is there away to ask the default UIImagePicker to sort its results and display latest ones or at least scroll to the end of the list after being presented?
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = NO;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
return YES;
}
As indicated in this This question
the solution involves adding an extra step before selecting an image with the line:
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
This displays the list of available photo libraries and scrolls to the bottom of the selected one.

iPhone:How to fetch image from photo library or camera with "edit" funcitionality like iPhone photo app

I know how to fetch image from photo library or camera in ios4.2.1
but in ios 5 there is new feature in photo app like if user wants to edit image or crop image then he is able to do such kind of things.
The same functionality I want to implement in my app when I grab image from camera or photo library.
the code by which I fetched image in ios 4.2.1 works also in ios 5 but by this code I am not able to edit or crop my image.
My code is as follows:
- (IBAction)btnCapturePressed:(id)sender {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc=[[UIImagePickerController alloc] init ];
ipc.delegate=self;
ipc.sourceType=UIImagePickerControllerSourceTypeCamera;
//btnUserImage.tag=-2;
[self presentModalViewController:ipc animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Nemo Rating" message:#"Camera capture is not supported in this device" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
-(void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo :(NSDictionary *)info
{
UIImage *imageToScale=[info objectForKey:UIImagePickerControllerOriginalImage];
// imageToScale=[imageToScale imageByScalingAndCroppingForSize:CGSizeMake(20,10)];
imageToScale=[imageToScale scaleToSize:CGSizeMake(95, 86)];
[btnUserImage setImage:imageToScale forState:UIControlStateNormal];
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if(version >= 5.0)
{
[[picker presentingViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
else
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
//[picker popViewControllerAnimated:YES];
[picker release];
}
}
This code simply give me the image but I am not able to edit it...
then is there any different code which make me able to edit or crop my image like photo app
for better understanding I upload followin screen shot. I take this screen shot from photo app.
thanks in advance.
I found one link which is not same as you want but it might help you
move and scale
As Devang has suggested, I am afraid that there is NO way you can get the inbuilt Edit from the Photos app.
There is no way you can get access to Private API. "Photos" app is the Apple's application and hence it has some features which are not accessible by the developers in Public API.
Now the point is that you can only create and instance of photo library or camera and grab an image from there. But there is no way you can access the "Edit" function of the Photos application.
If at all you require to do it, then you need to find a way to code all the functionalities by yourself.
Hope this helps you.

How can I browse a picture from iPhone picture library?

I am new in ios development. I am doing a photo cropper app.
I want to browse an image from the iPhone picture library by clicking browse button (that I added in my app) and load it to UIImageview that I placed in a view.
How can I browse the image ?.
Is it possible to browse the complete phone memory ? (Just like asp:FileUpload).
Is there any control available in iPhone to use just like asp:FileUpload ?
Thanks in advance.
Super easy to do!
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:YES];
and
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
[picker release];
// Edited image works great (if you allowed editing)
//myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
// AND the original image works great
//myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
// AND do whatever you want with it, (NSDictionary *)info is fine now
//UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[customImageView setImage:image];
customImageView.contentMode = UIViewContentModeScaleAspectFill;
}
got this code from stackoverflow, didn't save the URL, sorry.
The whole file system is not available, if you're running a non-jailbroken phone. Neither are there filesystem browser controls (for the same reason), However, you can browse the user's photo library, or even take a photo with the camera using UIImagePickerController. Docs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

Basic description on how to record video in iOs 4

Hey guys i was curious if anybody could give me a very brief description of how to make an app record video in iOs 4. I know how to do all the media and whatnot using the os 3 method of using the UIImagePickerController but I do not know if that is still available in iOs4 and if not, could someone please give me a very brief description on how to do it using the new method? (No code required, but is more than welcome.)
-Thank you!
It's pretty straightforward.
I just made a view-based app with a single button on the interface to test this. The button's action is - (IBAction)shootButtonPressed;
You have to check if the device supports video recording and then configure the image picker controller to only shoot video. This code will only work on an actual device.
In the main view controller header, I made it conform to two protocols: UIImagePickerControllerDelegate and UINavigationControllerDelegate
Then I implemented the button press method like this;
- (IBAction)shootButtonPressed;
{
BOOL canShootVideo = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if (canShootVideo) {
UIImagePickerController *videoRecorder = [[UIImagePickerController alloc] init];
videoRecorder.sourceType = UIImagePickerControllerSourceTypeCamera;
videoRecorder.delegate = self;
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
NSArray *videoMediaTypesOnly = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(SELF contains %#)", #"movie"]];
BOOL movieOutputPossible = (videoMediaTypesOnly != nil);
if (movieOutputPossible) {
videoRecorder.mediaTypes = videoMediaTypesOnly;
[self presentModalViewController:videoRecorder animated:YES];
}
[videoRecorder release];
}
}
You also have to implement two more methods to handle when a movie's shot & chosen and when the user cancels the video camera picker.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
// save the movie or something here, pretty much the same as doing a photo
NSLog(#"movie captured %#", info);
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
// process the cancellation of movie picker here
NSLog(#"Capture cancelled");
}
Super easy.
For more details, see the Multimedia Programming Guide --> About Audio and Video --> Using Video --> Recording and Editing Video. It's in the Apple Docs, although a little scattered for my taste.

UIImagePickerController with camera source: video trimming doesn't work

I am using UIImagePickerController to record a video with the sourceType set to UIImagePickerControllerSourceTypeCamera.
I have set allowsEditing to true so that the video can be edited before the picker returns. But after I edit the video using the trimming interface and press "Pick", I only get back the original recording in the delegate, not the trimmed version. What am I doing wrong? I am using iPhone OS 3.1.3. I remember this used to work in an earlier version but it seems to be failing in the latest OS. Any help is appreciated?
By the way i confirmed that if the source of the video is UIImagePickerControllerSourceTypeSavedPhotosAlbum, the trimming works in version 3.1.3. So trimming with source as the camera is failing. Interestingly with the camera-roll/photos-album as the source, a "Choose" button appears and soon after clicking it, the controller displays a message saying the "Video is being trimmed ... ". I don't get this message when using the camera source.
Here is a snippet of the code I am using to record a video using the camera source.
- (void) recordVideo {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentModalViewController:picker animated:YES];
[picker release];
}
My delegate implementation is as follows:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo: (NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
self.videoPath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
...
}
Thanks a lot,
kris.
Just ran into this myself ... and found this post when looking for a solution.
looks like the only way around this is to copy the file to your app's directory, then open the UIVideoEditorController ...
Anyone know if this UIImagePickerController newly-captured video not being trimmed issue is a bug in the SDK, or are we doing something wrong?