imagePickerController move and scale does not work - ios

Here is my code:
-(void) takePhoto
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
//imagePickerController.editing = YES;
imagePickerController.allowsEditing=YES;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
}
#pragma mark - Image picker delegate methods
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:NO completion:nil];
[self.Picture setImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
}
and I have implemented the delegates
UINavigationControllerDelegate,UIImagePickerControllerDelegate
The image is taken, I can see the move and scale box, but when I move it the box returns to the initial position - likes it bounces back.
Why is that?

Looks like this is caused because you are requesting the UIImagePickerControllerOriginalImage, according to the documentation this returns "the original, uncropped image selected by the user."
Try changing this to UIImagePickerControllerEditedImage.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerControllerDelegate_Protocol/UIImagePickerControllerDelegate/UIImagePickerControllerDelegate.html#//apple_ref/doc/constant_group/Editing_Information_Keys
Edit: Actually after re-reading the question a couple of times if the problem is occurring in the picker itself this probably won't help.

Related

UIImagePickerController is dismissing on didFinishPickingMediaWithInfo

From Apple Documentation.
"This supports taking more than one picture without leaving the interface, but requires that you hide the default image picker controls".
On [self.imagePicker takePicture] the delegate didFinishPickingMediaWithInfo is being called but is still leaving the interface.
Any idea how can i prevent the controller from being dismissed?Here is my code of UIImagePickerController with custom overlay.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = NO;
CameraOverlayView *overlay = (CameraOverlayView *)[self viewWithNibName:#"CameraOverlayView" owner:self];
overlay.frame = imagePicker.cameraOverlayView.frame;
imagePicker.cameraOverlayView = overlay;
overlay.imagePicker = imagePicker;
[self presentViewController:imagePicker animated:YES completion:nil];
overlay = nil;
I have same problem but i resolved this by using these classes in my code UzysAssetsPickerController for iOS
By using this i can select multiple images without dismissing the image picker. Hope this will help.
This solved my problem.Working perfectly now.Thank You everyone.
<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
#property(nonatomic,strong) UIImagePickerController *imagePicker;
overlay.imagePicker = _imagePicker;
overlay.imagePicker.delegate = overlay;
// may be it will help for you.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// if you want to dismiss controll then use the following code
[picker dismissViewControllerAnimated:YES completion:^{
}];
// if you wnat to being present it comment the above dismis code
}

Dismissing the image picker from the didFinishPickingMediaWithInfo method now impossible?

This seems like a simple question and I've seen similar ones answered but the answers just don't work (at least anymore). I have the following code in viewDidAppear:
UIImagePickerController *imagePicker;
imagePicker =[[UIImagePickerController alloc] init];
imagePicker.allowsEditing = YES;
{imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;}
imagePicker.delegate=self;
NSLog(#"ViewDidAppear");
[self presentModalViewController:imagePicker animated:YES];
NSLog (#"Modal Window Displayed.");}
This allows the user to select an image from the image library, which works. Once that image is picked, didFinishPickingMediaWithInfo gets called which has this code at the top of it:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSLog(#"Image Is Picked");
[[picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[self dismissModalViewControllerAnimated:YES];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
[self.navigationController popViewControllerAnimated:YES];
As you can see, I've tried several different ways found here on StackOverflow to get this to work. They all get ignored. No errors, just nothing happens; the picker view never goes away. What gives? I'm using xCode 7.2.1.
I have a similar place in my code where I present another modal view and also can't get rid of it.
The problem is that the didFinishPickingMediaWithInfo method doesn't actually dismiss the other view until it is DONE with it's execution (even if what's running in that method takes almost a minute!). By the time that method was done, I had already presented another viewcontroller modally. Almost all of the techniques I'd been trying all along actually still work.
If you present with presentViewController instead of presentModalViewController:
[self presentViewController:imagePicker animated: YES];
then
[self dismissViewControllerAnimated:YES completion:nil];
should work - perhaps the combination of different functions you are calling all at once is confusing things.
If this doesn't work, perhaps try presenting it with a slight delay with dispatch_after - it could be that presenting it within viewDidAppear is causing the issue:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.001 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
[self presentViewController:imagePicker animated: YES];
}
Below code works for me perfectly. Hope it helps.
in class.h
#interface class : UIViewController<UIImagePickerControllerDelegate>
{
UIImagePickerController *picker;
}
in class.m when getPhoto called, PickerViewController presented.
- (IBAction)getPhoto:(UIButton *)sender {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker2 didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker2 dismissViewControllerAnimated:YES completion:nil];
}
Globally declare your imagePicker like below
#implementation ViewController{
UIImagePickerController *imagePicker;
}
Display your image picker declared globally
- (IBAction)chooosePic:(id)sender {
imagePicker =[[UIImagePickerController alloc] init];
imagePicker.allowsEditing = YES; {imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;}
imagePicker.delegate=self;
NSLog(#"ViewDidAppear");
[self presentModalViewController:imagePicker animated:YES];
NSLog (#"Modal Window Displayed.");
}
didFinishPickingMediaWithInfo method update as below:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[imagePicker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Will Work

How to use camera inside my App controller

How can I open camera inside my app controller.
I don't want to present built in camera controller.
I want to make my own camera sort of app.
Any suggestion or guide will be highly appreciated.
You can easily use UIImagePickerController for this
Declare UIImagePickerController *imagePickerController; globally for the class
Declare protocols
#interface YourClassName : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePickerController setMediaTypes:#"public.image"]]; //specify image (not video)
[imagePickerController setShowsCameraControls:NO]; //hide default camera controls
[imagePickerController setNavigationBarHidden:YES];
[imagePickerController setToolbarHidden:YES];
[imagePickerController setAllowsEditing:NO];
[self.view addSubview:imagePickerController.view];
Use the takePicture method for the UIImagePickerController object like and assign it on a button action, like:
-(IBAction)btnTakePictureAct:(UIButton *)sender
{
[imagePickerController takePicture];
}
Use the delegate -imagePickerController:didFinishPickingMediaWithInfo: to get the image.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
}
See this, get an idea, make your custom camera controls.
Refer: UIImagePickerController Apple Doc

Loading my image on new screen

I have everything i want working up to the view you can see in the picture, i don't want the image to load on the same screen, how can i get it to load in a new screen. i have tried a few tutorials, i have had no luck as yet
The image that has been loaded from the gallery is the brick wall in the background.
the reason i want to load it in a new screen is so i can put a new toolbar that will allow me to drag images and overlay them on top of the image selected from taller or taken with the camera
Thanks in advance and sorry for asking about something that sounds so simple, I'm just very new to all this.
http://imageshack.com/a/img845/4808/9lz8.png
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
How do i open new screen when didFinishPickingMediaWithInfo
If you need to see me more code please let me know which, I'm not sure what code you need to see :) thank you for your reply.
If you want the image to load on a new screen, you'll need to create a second viewController, and add an imageView to that viewController.
then in your didFinishPicking method, instead of setting the image to the imageView of the current ViewController, instantiate a new imageController, set the imageView property of the new viewController, and then push your new viewController onto the navigation stack if you're using a navigation controller. If you're not using a navigation controller, you could just push the second view controller modally.
So in your didFinishPicking method it would be
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.imageView.image = chosenImage; //or whatever the imageView property is called of your new view controller
[self presentViewController:newViewController animated:YES completion:nil];
(I haven't tested this code - it's off the top of my head so reader caution advised and this is the modal method)
Let's try:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:^{
// I think you should not call `presentViewController` newViewController at this screen because it maybe be destroyed
// So, call newViewController at parentClass by delegate of block
// and assign new image to the screen which need to show
}];
}

How do I reference the picture I just took in iOS?

I'm writing an app that allows the user to take a picture and then shows it in an image view.
I get that I need to write a line of code similar to the following: _imageView.image = picker.image;, but I'm not sure what I need to substitute for picker.image. That is what I currently have and it gives me an error.
Basically, what I'm asking is how do I reference the picture that was just taken? Where does this picture go (in memory?) after you take it? How can I reference it later (like for displaying and saving and that sort of stuff)?
I've already read the official Apple documentation and looked at a few tutorials and the answer doesn't seem to be in any of them. As I've mentioned in previous posts, I tend to have a lot of trouble parsing the Apple documentation, so it's been mostly useless for me.
Thank you!
I use the following delegate method to get whatever picture a user picked from the photo picker view
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:false completion:nil];
image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
call the cameraTapped method on tapping your camera button
-(IBAction)cameraTapped:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
else
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:self];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// photo
_imageView.image = info[UIImagePickerControllerOriginalImage]];
[self dismissViewControllerAnimated:YES completion:nil];
}

Resources