How can I browse a picture from iPhone picture library? - iphone

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

Related

Resize taking photo through default camera

I am using UIImagePickerViewController to take photo from iPhone default camera in my App and storing it in Document directory. It is taking long time to complete the process and also it is displaying very slowly on tableview.Does resizing image help here?
-(IBAction)takePhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imgPicker animated:YES];
}
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
NSData *imageData = UIImagePNGRepresentation(pickedImage);
NSString *path = [SAVEDIMAGE_DIR stringByAppendingPathComponent:#"image.png"];
[imageData writeToFile:path atomically:YES];
}
Sure!
I do the following in my app:
store the image in an image store in a background thread
create a thumbnail (also in background thread), store this thumbnail in a core data table; in an field of type ID
So I get a smooth UI, where the User can take about a picture every 2 seconds.
The smoothness of the table views are also no problem. Although I populate the TableViewCells ImageViews also from a background-thread (preparing the image in the background, assigning to the UIImageView in the mainthread, of course).
I hope, that helps you. Further questions are welcome.
Some code for your convenience:
As Imagestore I use these: https://github.com/snowdon/Homepwner/blob/master/Homepwner/ImageStore.m
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self performSelectorInBackground:#selector(saveFoto:) withObject:info];
// you should add some code for indicating the save process
}
// saves the photo in background-thread
-(void)saveFoto:(NSDictionary*)info {
// the following is some stuff that I do in my app - you will probably do some other things
UIImage *image = [ImageHelper normalizeImageRotation: [info objectForKey:UIImagePickerControllerOriginalImage]];
UIImage *thumb = [ImageHelper image:image fitInSize:CGSizeMake(imgWidth, imgWidth) trimmed:YES];
NSString *myGUID = myGUIDCreator();
[[ImageStore defaultImageStore] setImage:image forKey:myGUID];
myCoreDataManagedObject.thumb = thumb;
[self performSelectorOnMainThread:#selector(showYourResultsInTheUI:) withObject:thumb waitUntilDone:NO]; // every UI-Update has to be done in the mainthread!
}

Handling UIIMagePickerController when compressing video screen appears

I am using UIImagePicker for selecting video from library and trying to use the video in my application.For this I am using code like this
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.delegate = self;
picker.mediaTypes=[NSArray arrayWithObject:(NSString*)kUTTypeMovie];
[self presentModalViewController:picker animated:YES];
Now the problem is that when any video is selected it shows compressing video message alongwith a progress bar.Meanwhile If I send my app in background I want to cancel this compression and dismismodalviewController so that corrupted compression does not occur.Is there any way to avoid this compression or to handle this so that result is either in success or in failure.Setting videoQuality is not solving the problem.
In my case, the URL coming from UIImagePickerControllerMediaType was nil. The solution was getting the video URL from UIImagePickerControllerReferenceURL:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSURL* url = [info objectForKey:UIImagePickerControllerReferenceURL];
//... read video with ALAssetsLibrary
}
Further info on how to read the video can be found here: How to save video from assets url

iPhone camera delay after taking picture in flash mode

iPhone camera delayed after taking picture in flash mode, I used UIImagePicker controller and used takePicture for capturing the picture, it is working well in all modes except if the flash mode is on. when it is on it is taking some time to process the image. why is this happening. Can anybody help me in this. my code is below.
to take picture i used
[picker takePicture];
after user took the picture...
imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModelviewControllerAnimated:YES];
}
I find it takes a while to process the picture under any sitaution. In my didFinishPickingMediaWithInfo I load up a view over the top of my main view to tell the user I'm processing the image.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *picture = [info valueForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
[self performSelectorInBackground:#selector(processImage:) withObject:picture];
_activityView = [[PSActivityView alloc] initWithFrame:CGRectZero];
_activityView.text = NSLocalizedString(#"Processing...", nil);
[self.view addSubview:_activityView];
[self.view bringSubviewToFront:_activityView];
}
The PSActivityView class sizes itself in the layoutSubViews method and the processImage method deals with the image and dismisses the _activityView when it's finished.
Seems to keep users happy with my app.

iPhone: How to change camera photo quality

I've not found a answer to this question anywhere, but this seems like a typical problem:
I am taking pictures from an iPhone 4, and I have to send these pics to a server through a POST-Request, but the server does not accept pictures that are bigger than 0,5 MB, so I have to compress the pictures before I send them. In order to achieve this, I am calling following method: "NSData *imageData = UIImageJPEGRepresentation(tempImage, 0.7);", which means: I am compriming the image data, and it takes a lot of time (about 10s / pic).
Is there any way to control the quality of the camera device in order to take low quality pictures?
Thanks in advance for helping.
Anything that will block the main thread should be done in a background thread, including converting an image to a JPEG. So you should start the JPEG conversion using performSelectorInBackground:withObject: and, when the conversion is done, pass the resulting NSData object back to the main thread.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
[self performSelectorInBackground:#selector(encodePhotoInBackground:) withObject:image];
}
- (void)encodePhotoInBackground:(UIImage*)image {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSData *imageData = UIImageJPEGRepresentation(image, 0.60);
[self performSelectorOnMainThread:#selector(saveImageData:) withObject:imageData waitUntilDone:NO];
[pool release];
}
- (void)saveImageData:(NSData*)imageData {
// Do something with the image
}

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?