Skip to content

Commit 57c7f13

Browse files
author
Zdravko
authored
Merge pull request #57 from EddyVerbruggen/issue-24-image-orientation-android
Selfie mode: added a 'cameraFacing' (front|rear) option
2 parents 7ff9be3 + ff92a7a commit 57c7f13

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

src/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ __Example 2__ shows how to take a picture using the NativeScript camera module.
8787
* __height__: The desired height of the picture (in device independent pixels).
8888
* __keepAspectRatio__: A boolean parameter that indicates if the aspect ratio should be kept.
8989
* __saveToGallery__: A boolean parameter that indicates if the taken photo will be saved in "Photos" for Android and in "Camera Roll" in iOS
90+
* __cameraFacing__: Start with either the "front" or "rear" (default) camera of the device. The current implementation doesn't work on all Android devices, in which case it falls back to the default behavior.
9091
9192
What does `device independent pixels` mean? The NativeScript layout mechanism uses device-independent pixels when measuring UI controls. This allows you to declare one layout and this layout will look similar to all devices (no matter the device's display resolution). In order to get a proper image quality for high resolution devices (like iPhone retina and Android Full HD), camera will return an image with bigger dimensions. For example, if we request an image that is 100x100, on iPhone 6 the actual image will be 200x200 (since its display density factor is 2 -> 100*2x100*2).
9293
Setting the `keepAspectRatio` property could result in a different than requested width or height. The camera will return an image with the correct aspect ratio but generally only one (from width and height) will be the same as requested; the other value will be calculated in order to preserve the aspect of the original image.

src/nativescript-camera.android.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export var takePicture = function (options?): Promise<any> {
6363

6464
takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPictureUri);
6565

66+
if (options && options.cameraFacing === "front") {
67+
takePictureIntent.putExtra("android.intent.extras.CAMERA_FACING", android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
68+
}
69+
6670
if (takePictureIntent.resolveActivity(utils.ad.getApplicationContext().getPackageManager()) != null) {
6771

6872
let appModule: typeof applicationModule = require("application");

src/nativescript-camera.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ export interface CameraOptions {
4141
* Defines if camera picture should be copied to photo Gallery (Android) or Photos (iOS)
4242
*/
4343
saveToGallery?: boolean;
44+
45+
/**
46+
* The initial camera. Default "rear".
47+
* The current implementation doesn't work on all Android devices, in which case it falls back to the default behavior.
48+
*/
49+
cameraFacing?: "front" | "rear";
4450
}

src/nativescript-camera.ios.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export var takePicture = function (options): Promise<any> {
155155
if (mediaTypes) {
156156
imagePickerController.mediaTypes = mediaTypes;
157157
imagePickerController.sourceType = sourceType;
158+
imagePickerController.cameraDevice = options && options.cameraFacing === "front" ? UIImagePickerControllerCameraDevice.Front : UIImagePickerControllerCameraDevice.Rear;
158159
}
159160

160161
imagePickerController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext;

0 commit comments

Comments
 (0)