diff --git a/camera/camera.android.ts b/camera/camera.android.ts index 5088c6207..72fa8da1b 100644 --- a/camera/camera.android.ts +++ b/camera/camera.android.ts @@ -2,16 +2,20 @@ import appModule = require("application"); import fileSystem = require("file-system"); import utils = require("utils/utils"); +import definition = require("camera"); import common = require("./camera-common"); var REQUEST_IMAGE_CAPTURE = 3453; -export var takePicture = function (width?, height?, keepAspectRatio?): Promise { +export var takePicture = function (options?: definition.CameraOptions): Promise { return new Promise((resolve, reject) => { try { var density = utils.layout.getDisplayDensity(); - var reqWidth = width ? width * density : 0; - var reqHeight = height ? height * density : reqWidth; + if (options) { + var reqWidth = options.width ? options.width * density : 0; + var reqHeight = options.height ? options.height * density : reqWidth; + var shouldKeepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio; + } var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); var dateStamp = createDateTimeStamp(); var tempPicturePath = fileSystem.path.join(appModule.android.currentContext.getExternalFilesDir(null).getAbsolutePath(), "cameraPicture_" + dateStamp + ".jpg"); @@ -34,7 +38,6 @@ export var takePicture = function (width?, height?, keepAspectRatio?): Promise 0 && reqWidth > 0) { if (shouldKeepAspectRatio) { diff --git a/camera/camera.d.ts b/camera/camera.d.ts index c4dc90fd8..0d86af126 100644 --- a/camera/camera.d.ts +++ b/camera/camera.d.ts @@ -11,5 +11,11 @@ declare module "camera" { * @param height - Optional parameter which defines the required height of the taken picture. * @param keepAspectRatio - Optional parameter which controls if the result picture will keep the aspect ratio of the picture taken by camera. */ - export function takePicture(width?: number, heigth?: number, keepAspectRatio?: boolean): Promise; + export function takePicture(options?: CameraOptions): Promise; + + export interface CameraOptions { + width?: number; + height?: number; + keepAspectRatio?: boolean; + } } diff --git a/camera/camera.ios.ts b/camera/camera.ios.ts index 5bf3cfbb9..30b7b3376 100644 --- a/camera/camera.ios.ts +++ b/camera/camera.ios.ts @@ -1,5 +1,6 @@ import imageSource = require("image-source"); import frame = require("ui/frame"); +import definition = require("camera"); import common = require("./camera-common"); class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePickerControllerDelegate { @@ -65,12 +66,18 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic } } -export var takePicture = function (width?, height?, keepAspectRatio?): Promise { +export var takePicture = function (options?: definition.CameraOptions): Promise { return new Promise((resolve, reject) => { var imagePickerController = new UIImagePickerController(); var listener = null; - var reqWidth = width || 0; - var reqHeight = height || reqWidth; + var reqWidth = 0; + var reqHeight = 0; + var keepAspectRatio = true; + if (options) { + reqWidth = options.width || 0; + reqHeight = options.height || reqWidth; + keepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio; + } if (reqWidth && reqHeight) { listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio }); }