Commit ee83e790 authored by Drahomír Karchňák's avatar Drahomír Karchňák

#612 IOS Camera Opener with portrait orientation.

parent 4a6d1414
......@@ -21,8 +21,15 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.iosrobovm.IOSApplication;
import com.badlogic.gdx.graphics.Pixmap;
import org.robovm.apple.coregraphics.CGAffineTransform;
import org.robovm.apple.coregraphics.CGPoint;
import org.robovm.apple.coregraphics.CGRect;
import org.robovm.apple.foundation.NSData;
import org.robovm.apple.uikit.UIDevice;
import org.robovm.apple.uikit.UIDeviceOrientation;
import org.robovm.apple.uikit.UIGraphics;
import org.robovm.apple.uikit.UIImage;
import org.robovm.apple.uikit.UIImageOrientation;
import org.robovm.apple.uikit.UIImagePickerController;
import org.robovm.apple.uikit.UIImagePickerControllerCameraCaptureMode;
import org.robovm.apple.uikit.UIImagePickerControllerCameraDevice;
......@@ -31,8 +38,11 @@ import org.robovm.apple.uikit.UIImagePickerControllerEditingInfo;
import org.robovm.apple.uikit.UIImagePickerControllerSourceType;
import org.robovm.apple.uikit.UIInterfaceOrientation;
import org.robovm.apple.uikit.UIInterfaceOrientationMask;
import org.robovm.apple.uikit.UIModalPresentationStyle;
import org.robovm.apple.uikit.UINavigationController;
import org.robovm.apple.uikit.UINavigationControllerDelegateAdapter;
import org.robovm.apple.uikit.UIPopoverArrowDirection;
import org.robovm.apple.uikit.UIPopoverPresentationController;
import org.robovm.apple.uikit.UIViewController;
import java.nio.ByteBuffer;
......@@ -44,11 +54,11 @@ public class IOSCameraOpener extends CameraOpener {
private class PickerControllerDelegate extends UINavigationControllerDelegateAdapter implements UIImagePickerControllerDelegate {
@Override
public void didFinishPickingMedia(UIImagePickerController picker, UIImagePickerControllerEditingInfo info) {
UIImage uiImage = info.getOriginalImage();
UIImage uiImage = getProperlyOrientedImage(info.getOriginalImage());
NSData nsData = uiImage.toPNGData();
ByteBuffer buffer = nsData.asByteBuffer();
byte[] imgData = new byte[buffer.capacity()]; //limit ?
byte[] imgData = new byte[buffer.capacity()];
buffer.get(imgData);
Pixmap pixmap = new Pixmap(imgData, 0, imgData.length);
......@@ -66,13 +76,13 @@ public class IOSCameraOpener extends CameraOpener {
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(UINavigationController navigationController) {
return UIInterfaceOrientationMask.All;
public UIInterfaceOrientation getPreferredInterfaceOrientation(UINavigationController navigationController) {
return UIInterfaceOrientation.Portrait;
}
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation(UINavigationController navigationController) {
return UIInterfaceOrientation.LandscapeLeft;
public UIInterfaceOrientationMask getSupportedInterfaceOrientations(UINavigationController navigationController) {
return UIInterfaceOrientationMask.All;
}
}
......@@ -91,12 +101,12 @@ public class IOSCameraOpener extends CameraOpener {
@Override
public UIInterfaceOrientation getPreferredInterfaceOrientation() {
return UIInterfaceOrientation.LandscapeRight;
return UIInterfaceOrientation.Portrait;
}
@Override
public UIInterfaceOrientationMask getSupportedInterfaceOrientations() {
return UIInterfaceOrientationMask.All;
return UIInterfaceOrientationMask.Portrait;
}
};
......@@ -111,6 +121,21 @@ public class IOSCameraOpener extends CameraOpener {
appController.presentViewController(imagePickerController, true, null);
}
/**
* Gets correctly oriented UIImage and disposes the old on.
*/
private UIImage getProperlyOrientedImage(UIImage image) {
if(image.getOrientation() == UIImageOrientation.Up) return image;
UIGraphics.beginImageContext(image.getSize(), false, image.getScale());
image.draw(new CGRect(new CGPoint(0, 0), image.getSize()));
UIImage normalizedImage = UIGraphics.getImageFromCurrentImageContext();
UIGraphics.endImageContext();
image.dispose();
return normalizedImage;
}
@Override
public void onCameraClose() {
delegate.dispose();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment