iOS UIImagePickerController annoying rotation (display picture) issue - ios

I'm writing app now which is using uiimagepicturecontroller.
Task is very simply. U need to take a picture a thing inside place in overlay (overlay is just a circle) and then display it. It works fine, when user holding the iPhone vertical. Picture is cropping and displaying fine. Problem is when user rotate their iPhone horizontal. I suppose camera is rotating and i can't display photo as i'd like.
Any ideas how to remove autorotatin?
Device orientations in my target->general is only Portrait
I tried override autorotate method in UIImagePickerController and it didn't works
Any idea how to fix it? Or any tricky tricky method to display image correctly?
Best regards,
David.
EDIT: Solution for this is use AVCam and write "own" class to take a picture.

i think it works:
-(void)imagePickerController:(UIImagePickerController *)pickerinput didFinishPickingMediaWithInfo:(NSDictionary *)info {
[pickerinput dismissViewControllerAnimated:YES completion:nil];
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
UIImageView *yourImgView=[[UIImageView alloc] initwithimage:image];
//please add this
yourImgView.transform = CGAffineTransformMakeRotation(M_PI/2);
}

Try this.
_img = [UIImage imageWithCIImage:_image scale:_imgScale orientation:_imgOrient];
_imgOrient = _img.imageOrientation;
_imgScale = _img.scale;

Related

App Crashing when taking picture on device - uipickercontroller

I have seen this question being asked many times before but I can't seem to get an answer that helps me. So here is my situation :
I have a user press a button that asks them if they want to take a picture or choose one from their album. When testing on my actual phone the choosing from album mode works, but the picture from camera goes all weird.
What happens : User is shown camera view -> user takes picture -> CRASH
The crash is not one in the console tho... I get a window on top of my xCode window saying :
App stopped unexpectedly due to Memory Pressure.
So I read that I need to resize the image I am getting from the camera before I display a small thumbnail for the user... I am doing that but to no avail... this has now become a consistent issue.
Here is my code :
(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:YES completion:nil];
//UIImage *img = [info objectForKey:UIImagePickerControllerOriginalImage];
CGRect rect = CGRectMake(0,0,320,480);
UIGraphicsBeginImageContext(rect.size);
//[img drawInRect:rect];
UIImage *picture1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_photoTaken setImage:picture1];
[self updateAppropriateCharacterCount];
[_userInputTextField becomeFirstResponder];
}
Let me explain what the variables are :
_photoTaken is a pointer to a UIImageView where I want to display the thumbnail. It is much smaller than 320 x 480 though.
Now I also have this method :
(void) takePhotoButtonPressed {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}
Finally before I did all this funny resize stuff I was setting the "img" variable to another pointer called "image" that was defined in my local implantation. I was using this to check (later in the code) if an image existed.
Any help would be appreciated, or some guidance.
Thank you much
EDIT
I also noticed that if I run my app for some time before going right to taking a picture it crashes before even showing the camera - I press take a photo and bam dead....
I have a project designed to be more memory efficient for taking pictures. The files will be larger than thumbnail, but it usually runs much lighter than UIImagePicker, and the final picture files are significantly smaller.
You can find it here

iPhone: Capture iOS Camera with Overlay View

In my application i am capturing picture through camera with overlay view & in the overlay view, there is a custom button through which i want to capture the whole screen.Overlay view is transparent at some points where i want to capture image. I am doing it like this:
- (IBAction)captue:(id)sender
{
[self setBackgroundColor:[UIColor clearColor]];
UIGraphicsBeginImageContext(self.frame.size);
[self.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
It is capturing the image of overlay view but at the camera view (the view where overlay is transparent and i want to show camera view there) it is capturing black color instead of a photo. Anyone please tell me am i doing something wrong?
I found Screen capture is the one of the thing to capture camera view with overlay. But i didn't get the preview layer in screen captured video(in case video recording). Look at MyAVControllerDemo code to get clear idea and i used IAScreenCaptureView to capture video, or simple snap shot. Now working properly.
Using AVFoundationFramework to fix your problem.
Referred this link: http://code4app.net/ios/Camera-With-AVFoundation/5003cb1d6803fa9a2c000000

iOS programatically taking a screen shot messes up the image

I want to take a screen shot every time user holds the screen for one second and then open up an email window to let the user send the image. But I have a strange problem; the image gets messed up if a gradient image is present (UIImage which has a PNG gradient loaded in it - will explain).
So I created a UILongPressGestureRecgnizer, set it's minimumPressDuration to 1.0f and added it to the main view as the gesture recognizer: [self.view addGestureRecognizer:myRecognizer]. The recognizer calls a method, lets say shareClicked. In which I want to capture the current screen and pop up the email composer with that image in it. Here is how I do it:
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:#"Share feature"];
[mailComposer setMessageBody:[NSString stringWithFormat:#"Im sharing this with you cause its cool."] isHTML:NO];
[mailComposer addAttachmentData:UIImagePNGRepresentation(image) mimeType:#"image/png" fileName:#"image"];
[self presentViewController:mailComposer animated:YES completion:NULL];
BUT, there is a problem. There is a table view present on the main view and in the third cell there is a gradient I mentioned earlier. Im not sure how to explain it but its something like this:
As visible on the image there is a gradient on the top and there is another one a bit lower. The top one gets rendered normally while the second one causes a strange problem. The gradient is not actually blue but its white and goes to transparent. Here is an image of the gradient on black surface:
Here is a screen shot from the simulator how it should look:
And finally here is how it gets rendered and displayed in the mail composer:
What am I doing wrong? What is the problem? Its not simulator's fault cause it's the same on mobile device as well. Its iOS7 if that makes any difference.
Just to be clear the top gradient is the same but radial and its rendered perfectly. Both gradients are subviews to tableview's cell. How to fix it? Hopefully we find a solution as I did spend some time to "craft" this question :)
Have a look to the recomended solution https://developer.apple.com/library/ios/qa/qa1703/_index.html#//apple_ref/doc/uid/DTS40010193 as UIGetScreenImage is no more allowed

calling "- (void) takePicture" returns non-foucsed image

I have an UIImagePickerController with my own camera overlay. In that overlay I have a button that the user can press to take a photo.
Currently, I have an IBAction on "Touch Up Inside" that will take a picture. self.imagePickerController is my reference to UIImagePickerController
- (IBAction)onSnapClicked:(id)sender {
[self.imagePickerController takePicture];
}
My problem is that, in the callback method. The image that I get back is always blurry. Please help
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get the original image
UIImage *originalImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
They are the same quality. You might have created a lag somewhere thus gives you the false sense of finish taking picture, while it is actually capturing.
Unless your button allows touch through. In that case, the camera always try to focus that part of your picture. You have to prevent that from happening. How to do that, look into my answer on this question : Exlusive touch in cameraoverlay view (of the camerapicker) in iOS?

For iPad Developers: How to view an image selected from photo library’s popover in a UIImageView, iPad

I am working on an application for iPad, it is working fine until i reached this point:
The app shows the popover for the photo library, but when I choose the photo, the popover doesn't hide, and I also want it to view the selected image in a UIImageView, however i do not know how.
I am sure there is something wrong in the didFinishpickingMediaWithInfo function. here is the function's code:
-(void) imagePickerController:(UIImagePickerController *)picker didFinishpickingMediaWithInfo:(NSDictionary *)info{
//bgImage is a UIImageView
bgImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Dismiss UIImagePickerController and release it [picker dismissModalViewControllerAnimated:YES];
[picker.view removeFromSuperview];
[picker release];
}
My first question is: What am I supposed to add to this function for viewing the selected photo in the UIImageView? (When I click on the photo from the photo library in the simulator, neither the photo library hide nor the image is viewed in the specified UIImageView)
2- I have read that I should've used UIImage instead of UIImageView.. Is this true? If yes, what about the interface builder? There is nothing called UIImage?
To close the image picker, use:
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
What you get from
bgImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
is not an UIImageView, it's a UIImage. To get it displayed, you need to have a UIImageView in your UI somewhere, and set the view's image with what you just got from the picker:
imageView.image = bgImage
Hope this helps

Resources