Image editing on iphone - iphone

In my app i need to select a image from photos library and then user should be able to crop or scale the the image. Can any one please help me?

UIImagePickerController should do the trick.
UIImagePickerController *picker = [UIImagePickerController new];
picker.delegate = self;
picker.allowsEditing = YES;
[yourViewController presentModalViewController:picker];
Then we need to implement the delegate method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
}

You can use a UIImagePickerController to let the user select an image from the photos library.

#denizen
The
[yourViewController presentModalViewController:picker]; needs an animated:BOOL.
Like: [yourViewController presentModalViewController:picker animated:YES];

You can also have a look at SSPhotoCropperViewController. It’s a custom view controller that provides a simple, configurable and easy-to-use UI for cropping and scaling photos in iPhone & iPod Touch apps.
For picking photos from the Photo Library, UIImagePickerController does well. However you cannot use it for the photos you get from another sources, say Flickr, FB etc.
Here is the tutorial and the source code on GitHub for SSPhotoCropperViewController.

Related

Imagepicker for AVCaptureSession

I implemented code for taking picture using AVCaptureSession. And i have button to pick image from Gallery. So, i need to use UIImagePickerController for picking image from gallery.
Is it possible to use UIImagepicker for picking Gallery and AVCaptureSession for taking picture. If i use this inside same app, appstore reject app or not?
Sure. You want to create your UIImagePickerController with a sourceType of UIImagePickerControllerSourceTypePhotoLibrary:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
I can't imagine that Apple would reject you for doing this in the same app that you're using AVCaptureSession - they're providing these classes to do exactly what you're proposing, after all.

Image Picker Controller

I am using the UIImagePickerController to take a picture, that works great, but do not want to use the stand image editor, instead I want to use my own custom image editor. I want to transition to that after I take the picture. I am using the method below to push a view controller after the image picker dismisses.
However, I want to push this before the image picker dismiss to avoid an awkward transition. Any ideas?
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info;
The image picker is already in a navigation interface, so you can push anything you like onto the image picker as a secondary (editing) interface:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* im = info[UIImagePickerControllerOriginalImage];
if (!im)
return;
SecondViewController* svc =
[[SecondViewController alloc] initWithNibName:nil bundle:nil image:im];
[picker pushViewController:svc animated:YES];
}
You will, however, have to interfere to prevent the image picker from navigating to its own secondary interface. The easy way to do that is to set picker.showsCameraControls = NO and substitute your own controls.
Also, I might be wrong about this, but since you are the navigation controller delegate I think you can just veto an attempt by the image picker to navigate to its own secondary interface. (EDIT: No, I guess not, sorry. The delegate gets a will and a did but not a should message.)

Regarding uiimagepickercontroller

In my application i have to upload a image and that image is taken from the ipad camera, now my query is when i choose the button "TakePicture" the cameraview opens can I resize the cameraview which captures the image.
Here is my code.
- (void) takePicture {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
Dont think so, that is an internal ui call,
You might be able to put some custom overlay on the camera view as quite a few other apps do, but to resize the internal camera view is not what apple wants us to do.
But then again, it would be a nice to have as we can use that for some really cool effects!
Do you mean view itself? No, the size couldn't be changed. If you mean size of taken/chosen image, user will be allowed to do resizing if you set allowsEditing to YES.

automatically start FrontCamera and capture image

I want to make a camera application in which i want to start front camera automatically and capture image without user interaction. thanks in advance.
In addition to Robin's answer, add the following statements (before presentModalViewController:) to ensure that if the device has a front camera, that should be opened by default
if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]){
self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; //skipping this was crashing my app with some ** Assertion failure.
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
Please note, if your app is compatible with devices running OS older than 4.0, you will have to put in conditional checks since cameraDevice property is available only in iOS 4.0 and later
The UIImagePickerController is a higher level abstraction to the camera. Have a look at AVFoundation examples to see how to get to the camera more directly.
The documentation for AVFoundation is here.
To do it while still using the picker, have a look at.1317978. Look around for some examples using UIGetScreenImage(). It used to be a private API but I think it is now allowed.
You might also want to look around at some examples concerning custom overlay, like this one.
I dont know how much you know about objective-c or iphone development. so I will tell how to take photos in your iphone app.
First you should get your self aquatinted with UIImagePickerController class
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html
here is some examples for the same from apple
http://developer.apple.com/library/ios/samplecode/PhotoLocations/
http://developer.apple.com/library/ios/samplecode/PrintPhoto/
http://developer.apple.com/library/ios/samplecode/PhotoPicker/
http://developer.apple.com/library/ios/samplecode/iPhoneCoreDataRecipes/
and next here is the code that will help you take the pics if you just place it in your .m file
- (void)selectPhotos
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageView.image = image;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
now get started.

Skip UIImagePickerController Preview View?

I'm using UIImagePickerController to allow my user to select a video from the asset library.
When the UIImagePickerController is initially displayed, it shows thumbnails for the various movies that have been recorded.
Once the user selects a movie, it displays a "preview" view which allows them to playback and potentially edit the selected movie.
Is there any way to avoid displaying this view and instead return the movie that was selected on the thumbnail screen?
Here is the code I'm using:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
I haven't tested this myself, though I'll be attempting this in my own application shortly. If you take a look at the UIImagePickerController showsCameraControls documentation, it alludes to the fact that if you eliminate the camera controls you can take as many photos as you want.
So theoretically if you set showsCameraControls to NO, and assign your own cameraOverlayView UIView to let the user take a photo, you can dismiss the image picker without the preview view from showing.
Perhaps that helps. You could listen with the NSNotificationCenter on #"_UIImagePickerControllerUserDidCaptureItem". If the user select the item, you could dismiss the imagePicker and do your thumbnail stuff.
I had a similar issue, to remove an overlay on the preview view and could solve it with this approach.