Upload two images from UIImagePicker - ios

I tried to upload the two images one by one from UIImagePicker. UIImagePicker working good for single image. With UIImagePicker input i uploaded those photos into web server. For single image uploading into web server its working fine, But instead of two images one image is saving two times. This is the first time I am working on UIImagePicker. I don't know exactly where should I do changes to make it for uploading two images.
- (void)takePhoto:(UIButton *)sender {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alertView show];
}
else{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
}
- (void)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
chosenImage = info[UIImagePickerControllerEditedImage];
chosenImage1=info[UIImagePickerControllerEditedImage];
chosenImage2=info[UIImagePickerControllerEditedImage];
imageView.image = chosenImage;
frstCmpImgView.image= chosenImage1;
scndCmpImgView.image=chosenImage2;
if ([self.navigationItem.title isEqual: #"CLOTHING"]) {
NSLog(#"cloth page");
[self clothview];
}
else if([self.navigationItem.title isEqual: #"FACE PHOTO"]){
[self hideButtns];
NSLog(#"face page");
}
else{
//----compare object--
if ([cmparObjLabel.text isEqualToString:#"Choose the 1st Object"]) {
[self afterUploadFrstCmpObj];
}
else if ([cmparObjLabel.text isEqualToString:#"Choose the 2nd Object"])
{
[self afterUploadScndCmpObj];
}
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}

You have to use array for adding image in each and every click of take photo because image picker only fetch image one at a time , another option You can user ELCAlbumPicker to select multiple image and add these image over array and use them.

Related

objective c - after picking image from gallery or camera - needs to enable rotate, flip editing

After picking the image from gallery or camera - needs to enable rotate, flip editing How can i acive that.Here my code :
-(void)photofromCamera
{
#try
{
NSLog(#"2");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}
#catch (NSException *exception)
{
[self showAlert:#"Camera is not available"];
}
}
-(void)photofromGallery
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
So after the delegate method :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self.imageDeletionButton setHidden:NO];
UIImage *chosenImage = [info valueForKey:UIImagePickerControllerEditedImage];
self.PostImageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
As if now, if i pick any image from gallery, camera - i needs to show the crop, flip, rotation.please help me out how can i achive that.
Thanks in advance !!!
You can use the swift based framework IGRPhotoTweaks for rotate, flip and crop the image.
You can check the https://github.com/IGRSoft/IGRPhotoTweaks for git and
https://cocoapods.org/pods/IGRPhotoTweaks for cocoapods.
In the framework cropAction() and changedAngel(value: radians) are the 2 methods that you need to try to achieve your requirement.

UIImagePickerController won't cancel, getting message about detached ViewControllers

I've not seen these two issues compounded together, so I figured I'd ask.
PhotoViewController
-(void)viewDidAppear:(BOOL)animated
{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerEditedImage];
if(!image) image = info[UIImagePickerControllerOriginalImage];
picker.delegate = self;
[self setPhotoForNextVC:image];
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"givePhotoToGiveDetailsSegue" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
Selecting a photo works, but when I press cancel the UIImagePickerController keeps coming back up, and I get the error:
Presenting view controllers on detached view controllers is discouraged <UINavigationController: 0x10b38b560>.
I had faced this problem before as well.
For me it turned out to be that, especially in ViewDidAppear.
The OS doesn't like to put up new controllers right after another appears.
Make another method that handles this.
(void)bringUpCameraController {
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:picker animated:YES completion:NULL];
}
My workaround :[self performSelector:<(bringUpCameraController)> withObject:<(nil)> afterDelay:<(2.0)>]
this will get rid of the message.
Look up the tree to PhotoViewController's hierarchy. It's probably not the root. I had this happen.
The error message is literal.

How to save the selected image in UIImagePicker controller?

I can take a photo and it shows in imageviewn but as soon as I leave detailviewn and go to back to detailviewn its disappear. How should the image always be saved?
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (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];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
Check your IBOutlet Connection in xib file and You have to save the image taken in documents directory of your application , unless you cannot view the selected image

ioS7: Capture multiple images from camera and store in array

guys.
I'm trying to capture multiple images from the camera in iOS7, when I capture the first image and click in in "Use Photo", then it's store the image in a array in didFinishPickingMediaWithInfo. When the camera appear again, I see the last image in background but I can't see the camera movement. I know the camera is enabled, because it's searching faces. The code is below:
- (IBAction)openTour:(id)sender
{
_counter=0;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
imagePicker = nil;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
UIImage *image= [info objectForKey:UIImagePickerControllerEditedImage];
[ _imageArray addObject:image ];
_counter++;
if ( _counter<5 )
{
[self dismissViewControllerAnimated:NO completion:nil];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:nil];
imagePicker = nil;
}
}
else
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
Does anyone know what is happening?
Thanks in advance!
Set showsCameraControls = NO;
Use cameraOverlayView property.
In the action of your camera button call takePicture method.
Keep adding UIImage objects received by the method
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

move and scale bounces back

As you can see in this video it bounces back whenever I try to crop or move the crop box. I can't find any way to do this and I think my code is correct. How am I suppose to do this?
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Device has no camera"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (IBAction)takePhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
If image is too far away use this method to animate it back:
[UIView animateWithDuration: animations: completion:]
animations: is a block and it will change e.g CGRects over a duration, if you want to change the image position you add [image setRect:(CGRectMake(orginPosition.x, orginPosition.y, size.width, size.height))];
completion: is a block but isn't required.

Resources