Taking Photos in landscape having issues in my iOS application - ios

I take photos using UIImagePickerController, source type is UIImagePickerControllerSourceTypeCamera.
After i captured, the image editing is changing depending upon the orientation. Herewith i attached my snapshot.
Image 1 : i took this image in portrait mode.
Image 2 : i took this image in landscape mode. here, the top portion is in black color.
My code is :
UIImagePickerController *pickerCamera = [[UIImagePickerController alloc] init];
pickerCamera.delegate = self;
pickerCamera.allowsEditing = YES;
pickerCamera.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:pickerCamera animated:YES completion:NULL];
I want to rotate the image to portrait. Please help me to solve this issue.

Related

Circular crop image while picking it from gallery using ImagePickerViewController

UIImagePickerController* libraryUI = [[UIImagePickerController alloc] init];
libraryUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
libraryUI.delegate = self;
libraryUI.allowsEditing = YES;
[self presentViewController:libraryUI animated:YES completion:nil];
I am using this code to open image picker view and pick an image from gallery. I also set the property "allowsEditing" to "YES" in order to enable the crop image functionality. Now the main issue is that the picker view opened with rectangular crop option. What I want is to get circular crop image option and also want to set the crop circle size (increase or decrease crop circle size).
Since it is not available by default, I will suggest you to use this library:
TOCropViewController
It comes with some other features other than circular crop as well. Objective-C and Swift versions are both available

I used a custom view to preview my UIImagePicker preview, how can I extract the same region from the resulting image as was previewed?

In my view I have a UIView that I use to preview the camera. It's a lot smaller than the regular preview view (128x128). I initialise the UIImagePickerController like this:
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
self.picker.showsCameraControls = NO;
self.picker.view.frame = self.profilePictureView.frame;
I then use [v addSubview:self.picker.view]; to show the camera's preview within my custom UIVIew. So far this works as intended, I see the part of the camera preview that overlaps my custom view in that view (essentially masking the preview with my custom view).
Now I'm trying to get what is displayed in my UIView into a UIImage (resulting in a 128x128 image). I tried using the delegation methods, but I only get the full size image from the camera there. I also tried taking a screenshot from the view but I got lost...
How can I create a UIImage with the exact same content as the view I use to render the camera preview, including size, offset and ratio?

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

UINavigation Bar changing tint after using UIImagePickerController

I have a app that can attach a photo to an NSAttributedString in a textView. The UI design has a blue-grey navigation bar with white text.
However, after I use the UIImagePicker, the tint of the NavigationController changes to black text.
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
_imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
_imagePickerController.sourceType = sourceType;
_imagePickerController.delegate = self;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
_imagePickerController.showsCameraControls = YES;
}
[self presentViewController:_imagePickerController animated:YES completion:nil];
}
I'd post an image of the view before launching the UIImagePicker but I don't have enough reputation points (and I don't really know how to get them either).
And I'd post the image after launching the image picker and picking one and returning from the UIImagePicker, but again, not enough reputation points.
Anyone have any ideas if this is 'normal' or a bug ion iOS? Any suggestions on a workaround?
P.S. If you want to see the images, I can email them to you. Any advice is appreciated.
This indeed seems to be a bug, and has been present since iOS 7 beta 6 (or earlier).
There is another SO post about this with some solutions: UIImagePickerController breaks status bar appearance
This problem can be avoided by changing picker's modal presentation class to be different than full screen (e.g. UIModalPresentationPageSheet)
Code:
imagePickerController.modalPresentationStyle = UIModalPresentationPageSheet;

Camera Preview not filling iPad screen in Landscape

My app is iPad only, and supports only Landscape View.
I have a UIImagePickerController which loads the Camera.
I set it up with the following code:
m_Pickercontroller=[[UIImagePickerController alloc] init ];
m_Pickercontroller.sourceType = UIImagePickerControllerSourceTypeCamera;
m_Pickercontroller.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
m_Pickercontroller.cameraDevice = UIImagePickerControllerCameraDeviceRear;
m_Pickercontroller.showsCameraControls = YES;
m_Pickercontroller.navigationBarHidden = YES;
m_Pickercontroller.toolbarHidden = YES;
m_Pickercontroller.wantsFullScreenLayout = YES;
m_Pickercontroller.allowsEditing=NO;
It is presented with [self presentViewController:m_Pickercontroller animated:YES completion:nil]; I have also tried with a Modal and get the same result.
This occurs on first open of the view only. If you reopen the camera or retake the picture, it goes away.
I have also tried setting the m_Pickercontroller frame size, both before and after it is loaded.
Here is what it looks like, black area is empty, white area is the camera preview. Ignore the white line overlay, that is part of the app.
Ok, so this makes no since whatsoever but what was causing this was the animation:yes
I changed [self presentViewController:m_Pickercontroller animated:YES completion:nil]
to [self presentViewController:m_Pickercontroller animated:NO completion:nil]
and this issue has fixed itself. apparently iOS does not resize the camera preview after animating the view in.

Resources