UIImagePickerController's cameraOverlayView is offset after taking photo - ios

When you implement a cameraOverlayView for a UIImagePickerController, this view appears while you're taking the photo and after the photo has been taken, providing you with an opportunity to cancel or retake the photo. The problem I'm seeing is if your cameraOverlayView is on top of the photo preview area, when you take the photo and it shows you the preview, the photo you took doesn't align with the cameraOverlayView anymore. The entire photo preview pane has been moved down ~50 points while the cameraOverlayView has stayed in place. This is a problem when you need the photo to be aligned perfectly with the view.
How can this be adjusted so the two are perfectly aligned - while taking the photo and after it has been taken?
Notice how the whole preview area is pushed down after taking the photo.

I had a similar problem and came up with the following workaround:
if (IPhone5 || IPhone5c || IPhone5s)
{
imagePicker.cameraViewTransform = CGAffineTransformTranslate(imagePicker.cameraViewTransform, 0, 30);
}
else if (IPhone6 || IPhone6Plus)
{
imagePicker.cameraViewTransform = CGAffineTransformTranslate(imagePicker.cameraViewTransform, 0, 44);
}
This ensures that the picture that was taken will have approximately the same center as the camera preview layer (in portrait orientation).

Related

QuickBlox iOS WebRTC Video View Size

I'm trying to get my QBRTCRemoteVideoView to present a full-screen video output, similar to FaceTime or Skype.
However, using AutoLayout in my project, and setting the constraints to lead and trail to the superview, the video I get back does not follow those constraints. It shows with black borders on the top and bottom.
Even using the following properties:
videoFormat.width = 320; // or anything
videoFormat.height = 568; // or anything
Does not seem to change the dimensions of the video. Any advice for me here on controlling the video output view?
You can only set a specific width and height for video, to see what kind of video formats are supported by your device, call:
[QBRTCCameraCapture formatsWithPosition:AVCaptureDevicePositionFront];
// or AVCaptureDevicePositionBack
// or just get the currentPosition from your QBRTCCameraCapture instance

Screenshot everything on display

I am trying to take a screenshot of absolutely everything that is displayed on the iPhone display, in the same way that pressing the home + power buttons together does. The code I currently have to screenshot is this:
func screenShotMethod() {
//hide UI
buttonTrigger.hidden = true
//take screenshot
let layer = UIApplication.sharedApplication().keyWindow!.layer
let scale = UIScreen.mainScreen().scale
UIGraphicsBeginImageContextWithOptions(view.frame.size, false, scale);
layer.renderInContext(UIGraphicsGetCurrentContext()!)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
//show UI
buttonTrigger.hidden = false
}
The point is that I am using the camera and putting a picture over any face it detects, and the easiest way to save that to the camera roll is just to hide the UI and screenshot the screen. With this method however, I get a screenshot of the face tracking picture, in the correct position and size, but not of what the camera sees underneath - just white. I am enabling the camera using the CameraEngine framework in the viewDidLoad() like this:
override func viewDidLoad() {
super.viewDidLoad()
self.cameraEngine.startSession()
Is there a better way to screenshot everything to behave like the hardware induced method? Or how could I include what the camera sees in the screenshot?
Thank you!
UPDATE: In case anyone in the future wants to know how I fixed this, because I can't screenshot things I'm not drawing myself, I solved this issue by taking a picture with the camera and setting that image as the background of the view, and then performing the screenshot function and it works!
Starting in iOS 9 it is no longer possible to take a screenshot that includes elements of the screen not drawn by your program. You can only capture your application's views and layers. Apple doesn't expose the function that is triggered by power+home to third party developers.

Swift - force square photo from library and camera

I'm building an app and I need to FORCE the user to upload square pictures (just like Instagram does), however I'd like to avoid programming an interface from scratch as we're short in time.
It is important to note that the USER must CHOOSE which part of the image he/she wants to show, so cropping the image programatically without asking the user is out of the question.
I've managed to get this to work via camera, however via library I can't seem to force the user to use a square image. Here's the code I have:
func presentGallery(){
// from library
picker.allowsEditing = true
picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
presentViewController(picker, animated: true, completion: nil)
}
Then on my imagepickercontroller:
var chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage
However I don't get the desired result. It would be fine if the "minimum zoom" was to show 100% of the height of the image, or if I could add a white/black background to the top and bottom of the image.
Here's the problem:
Instead of something like this:
My app needs to work starting from iOS7.
You should do some sort of check to make sure that the picture is square if they're picking from their library.
Once you get the image (using imagePickerController didFinishPickingMediaWithInfo), then get the image with [info objectForKey:UIImagePickerControllerOriginalImage];. Once you've done this, perform the check:
if (image.size.height != image.size.width) // Show some alert
What might be an even better solution is creating a view which allows the user to pick any photo, and then choose a square part of the photo to import into your app, like Instagram does.

iOS, some questions about camera control

I am newbie to iOS programming.
I have a few simple questions.
After picking image from gallery or taking a picture from camera, I want to select
rectangle area like android
UIImagePickerController * picker =[[UIImagePickerController alloc] init];
picker.delegate=self;
picker.allowsEditing=YES;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
When I use this code, I can't resize my area as you see below
.
It is related to first question.
As you see my image is resized and changed to different ratio.
But I want image is fixed with original ratio.
Anyone knows how to use camera in iOS simulator?
Question 3: You cannot use the camera function in simulator. That is one of the limitations. See this document from Apple Developer page: https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/iOS_Simulator_Guide/TestingontheiOSSimulator/TestingontheiOSSimulator.html
Question 2: below
This is answer is from this link: How to make UIImageView automatically resize to the size of the image loaded
UIImage img = [UIImage imageNamed:#"myImage.jpg"];
[imageView setImage:img];
imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,
img.size.width, img.size.height);
"This will however not change the layout of view it is contained within, you can make it change the sizes of the other views automatically under iOS 6 using Layout Constraints. If you are an Apple Developer you can watch the WWDC instruction videos, they explain how that system works quite well."
It's the best answer I have as it is the way I use setting image sizes in a view.

iOS7 UIImagePickerController allowsEditing not working correctly

In someViewController:
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:^{
}];
I take a photo and get to the next screen where (due to allowsEditing = YES;) I have an option to crop my photo into square shape. White square rectangular appears on an initial position over the photo I've taken and I try to move it around. I can drag it, but every time I release the finger, it goes back to the position it held initially. The are no glitches. When I release the finger, white framed rectangular animates with easeOut animation back to the position where I dragged it from.
It is not the same as if allowsEditing is set to NO. If it is set to NO, than a cropping rectangle does not even appear.
Previously, I thought that the problem appears only on iOS 7, but now I realise that it happens on all iOS versions. I don't understand how this happened, but it started when I started using Xcode 5 and building for iOS7. I kept Xcode 4.6.3 on my Mac so I tried to build this app again with the older Xcode, but it did not fix anything.
I also need to mention that when I load an image from photo library, cropping works fine, like it is supposed to. I have problems only when taking a new photo.
Furthermore, when initial crop rectangle appears, although I am unable to drag that rectangle around the photo, I can still zoom in and out. When I zoom in, I can then drag this (smaller) cropping rectangle around the photo but ONLY within boundaries of initial rectangle's position & size. If I cross that boundary, my cropping rectangle animates back to the inside of the invisible boundaries.
Anyone, please help...
It seems like this is a bug with UIImagePickerController. I was trying to figure out what I did wrong. But then I started a couple of blank new projects just to test this functionality. I also checked out the Apple's official sample code:
https://developer.apple.com/library/ios/samplecode/photopicker/Introduction/Intro.html

Resources