mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
camera takePicture parameters wrapped in an option object.
This commit is contained in:

committed by
Rossen Hristov

parent
267ce57d09
commit
d86a19cb28
@ -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<imageSource.ImageSource> {
|
||||
export var takePicture = function (options?: definition.CameraOptions): Promise<imageSource.ImageSource> {
|
||||
return new Promise<imageSource.ImageSource>((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<i
|
||||
var finalBitmapOptions = new android.graphics.BitmapFactory.Options();
|
||||
finalBitmapOptions.inSampleSize = sampleSize;
|
||||
var bitmap = android.graphics.BitmapFactory.decodeFile(tempPicturePath, finalBitmapOptions);
|
||||
var shouldKeepAspectRatio = (keepAspectRatio === null || keepAspectRatio === undefined) ? true : keepAspectRatio;
|
||||
var scaledSizeImage = null;
|
||||
if (reqHeight > 0 && reqWidth > 0) {
|
||||
if (shouldKeepAspectRatio) {
|
||||
|
8
camera/camera.d.ts
vendored
8
camera/camera.d.ts
vendored
@ -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<imageSource.ImageSource>;
|
||||
export function takePicture(options?: CameraOptions): Promise<imageSource.ImageSource>;
|
||||
|
||||
export interface CameraOptions {
|
||||
width?: number;
|
||||
height?: number;
|
||||
keepAspectRatio?: boolean;
|
||||
}
|
||||
}
|
||||
|
@ -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<imageSource.ImageSource> {
|
||||
export var takePicture = function (options?: definition.CameraOptions): Promise<imageSource.ImageSource> {
|
||||
return new Promise<imageSource.ImageSource>((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 });
|
||||
}
|
||||
|
Reference in New Issue
Block a user