iPhone How to present photos from my documents directory? - iphone

I have been using UIImagePicker controller for taking photos and saving it to my documents directory. Now i want to be able to present them to user for picking. UIImagePicker has neat functionallity
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
When I set this property all images from library are presented. Is there some way I can use UIImagePicker to present my photos from documents directory?

The only supported sources for the UIImagePicker are library, camera or saved photo album. See UIImagePickerControllerSourceType # http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
enum {
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
};
typedef NSUInteger UIImagePickerControllerSourceType;

Related

What are the methods/classes I need to create an iPhone upload photo form?

Currently I have a view with an ImageViewer and 2 buttons (Browse & Upload). I'm currently searching for methods to display the iPhone photo album once the button is pressed.
I've looked at this example here but I assume this one is the method you call when you want to upload the photo into the server.
Objective C: How to upload image and text using HTTP POST?
I'd like to duplicate the functionality of a web upload form.
1. Click button to browse folders.
2. Choose photo and display in a container.
3. Click Upload to upload photo into the server.
**Update:
Found some nice tutorials that helped me start with my iPhone app photo upload form.
Using UIImagePickerController
http://iosdevelopertips.com/camera/camera-application-to-take-pictures-and-save-images-to-photo-album.html
http://trailsinthesand.com/picking-images-with-the-iphone-sdk-uiimagepickercontroller/
Adding images to iPhone Simulator
You will have to use UIImagePickerController class
Here is the class reference for UIImagePickerController
Initialize the picker controller in your button event handler method.
Then set the UIImagePickerControllerDelegate to your current viewController
Here is the class reference for UIImagePickerControllerDelegate
picker.delegate = self;
Set the UIImagePickerControllerSourceType of picker to UIImagePickerControllerSourceTypePhotoLibrary
picker.UIImagePickerControllerSourceType = UIImagePickerControllerSourceTypePhotoLibrary
Then present the pickerViewController (if your target device is an iPad, present the imagePickerView in a popOver control)
Once user selects an image picker controller will automatically call its delegate method
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
You can get the selected image by accessing the value for UIImagePickerControllerOriginalImage from the NSDictionary *info
Then you can use the image for uploading to server as mentioned in the post link
These are some tutorials for UIImagePickerController
Tutorial one
Tutorial two
Tutorial three
for getting images from iPhone library you have to use UIImagePickerController.
m_imagePickerController = [[UIImagePickerController alloc] init];
m_imagePickerController.delegate = self;
m_imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
hope this will help you

How to use UIImagePickerController properly on the iPad?

From the documentation of UIImagePickerController:
On iPad, present the user interface using a popover. Doing so is valid
only if the sourceType property of the image picker controller is set
to UIImagePickerControllerSourceTypeCamera.
So what they say is:
On iPad I MUST use a UIPopoverController to display the image picker.
But at the same time, it is limited to UIImagePickerControllerSourceTypeCamera
How about the other source types such as UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeSavedPhotosAlbum?
In my case I want the user to choose from his photo library and not take a picture with the camera.
Is there a way to use UIImagePickerController to pick photos from a library on the iPad?
I suspect that documention has a typo in it. I've successfully used UIImagePickerController with other sourceTypes on iPad - just had to make sure it was in a UIPopoverController.

How to record video in iPhone using Objective-C?

I have a map application in which there is a button named video. If a user clicks on the video button he can record video at any location he like and simultaneously play the video.
How can I do this? My code is as follows:
-(IBAction)video:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; NSArray *sourceTypes = [UIImagePickerController availableMediaTypesForSourceType:picker.sourceType]; if (![sourceTypes containsObject:(NSString *)kUTTypeMovie ]){ NSLog(#"device not supported"); return; } picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeVideo]; picker.videoQuality = UIImagePickerControllerQualityTypeHigh; [self presentModalViewController:picker animated:YES]; }
From Apple Programming guides
Starting in iPhone OS 3.0, you can
record video, with included audio, on
supported devices. To display the
video recording interface, create and
push a UIImagePickerController object,
just as for displaying the
still-camera interface.
To record video, you must first check that the camera source type
(UIImagePickerControllerSourceTypeCamera)
is available and that the movie media
type (kUTTypeMovie) is available for
the camera. Depending on the media
types you assign to the mediaTypes
property, the picker can directly
display the still camera or the video
camera, or a selection interface that
lets the user choose.
Using the UIImagePickerControllerDelegate
protocol, register as a delegate of
the image picker. Your delegate object
receives a completed video recording
by way of the
imagePickerController:didFinishPickingMediaWithInfo:
method.
On supported devices, you can also pick previously-recorded videos from a
user’s photo library.
For more information on using the image picker class, see
UIImagePickerController Class
Reference. For information on trimming
recorded videos, see
UIVideoEditorController Class
Reference and
UIVideoEditorControllerDelegate
Protocol Reference.
Once you have the video in your UIImagePickerController delegate you can then save it to your app's documents directory using standard file operations.

UIImagePickerControllerSourceTypeCamera crashes in IPHONE Simulator?

Is it a known issue that if you try to test your UIImagePickerController using the Camera as a source type then the simulator will crash?
I have the following code:
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
[self.imgPicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:self.imgPicker animated:YES];
[imgPicker release];
Running this in simulator, I get an objc-exception-throw error on the stack # -[UIImagePickerController setSourceType:].
Now if I set the source type to the Photo Library though, everything runs smoothly and fine? What's the deal?
Simulator doesn't have the camera and can't simulate to take a picture (it would have been nice to use the isight but Apple has not been so kindly). However Your code is not safe because, for example, old ipod touch doesn't have a camera and in this case your app will crash on this device.
As Apple suggest in UIImagePickerController documentation:
To use an image picker controller
containing its default controls,
perform these steps:
1.Verify that the device is capable of picking content from the
desired source. Do this calling the
isSourceTypeAvailable: class method,
providing a constant from the
“UIImagePickerControllerSourceType”
enum.
2.Check which media types are available, for the source type you’re
using, by calling the
availableMediaTypesForSourceType:
class method. This lets you
distinguish between a camera that can
be used for video recording and one
that can be used only for still
images.
3.Tell the image picker controller to adjust the UI according to the
media types you want to make
available—still images, movies, or
both—by setting the mediaTypes
property.
4.Present the user interface by calling the
presentModalViewController:animated:
method of the currently active view
controller, passing your configured
image picker controller as the new
view controller.
5.When the user taps a button to pick a newly-captured or saved image
or movie, or cancels the operation,
dismiss the image picker using your
delegate object. For newly-captured
media, your delegate can then save it
to the Camera Roll on the device. For
previously-saved media, your delegate
can then use the image data according
to the purpose of your app.
So you have to call isSourceTypeAvailable and set your sourceType consistently.

Question about iPhone 3GS Image Picker Controller

I am writing a simple video uploader application on iPhone 3GS where I first direct the user to photos album, and then select the video to share or upload. I am using the UIImagePickerController in the following way:
videoPickerCtrl = [[UIImagePickerController alloc] init]; videoPickerCtrl.delegate = self; videoPickerCtrl.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; videoPickerCtrl.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoPickerCtrl.sourceType];
videoPickerCtrl.allowsImageEditing = NO; videoPickerCtrl.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie]; [window addSubview:videoPickerCtrl.view];
But I can see that once the controller is invoked, there is a disturbing video trimming interface that is presented. Once I press "choose", the video is always trimmed no matter whether I touch the trimming controls or not. Is there any way to get around this trimming interface and directly get the path of the video file ?
You don't specify what version of the iPhone SDK that you're using.
If you're using SDK 3.0, there's no way that I'm aware of to eliminate the trimming interface.
If you're using SDK 3.1, try setting UIImagePickerController.allowsEditing to false. In 3.1 the allowsImageEditing has been deprecated for a more general allowsEditing property.
The trimming you see is the iphone copying the video file into your apps tmp directory allowing you to access it. Look up iphone app sandboxing if you still don't get it.