mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Image from camera will be resized to screen dimensions.
This commit is contained in:
@ -3,6 +3,7 @@ import * as utilsModule from "utils/utils";
|
|||||||
import * as applicationModule from "application";
|
import * as applicationModule from "application";
|
||||||
import * as imageSourceModule from "image-source";
|
import * as imageSourceModule from "image-source";
|
||||||
import * as cameraCommonModule from "./camera-common";
|
import * as cameraCommonModule from "./camera-common";
|
||||||
|
import * as platform from "platform";
|
||||||
|
|
||||||
var REQUEST_IMAGE_CAPTURE = 3453;
|
var REQUEST_IMAGE_CAPTURE = 3453;
|
||||||
|
|
||||||
@ -56,13 +57,13 @@ export var takePicture = function (options?): Promise<any> {
|
|||||||
let imageSource: typeof imageSourceModule = require("image-source");
|
let imageSource: typeof imageSourceModule = require("image-source");
|
||||||
let options = new android.graphics.BitmapFactory.Options();
|
let options = new android.graphics.BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
android.graphics.BitmapFactory.decodeFile(picturePath, options);
|
let bitmap = android.graphics.BitmapFactory.decodeFile(picturePath, options);
|
||||||
|
|
||||||
let sampleSize = calculateInSampleSize(options.outWidth, options.outHeight, reqWidth, reqHeight);
|
let sampleSize = calculateInSampleSize(options.outWidth, options.outHeight, reqWidth, reqHeight);
|
||||||
|
|
||||||
let finalBitmapOptions = new android.graphics.BitmapFactory.Options();
|
let finalBitmapOptions = new android.graphics.BitmapFactory.Options();
|
||||||
finalBitmapOptions.inSampleSize = sampleSize;
|
finalBitmapOptions.inSampleSize = sampleSize;
|
||||||
let bitmap = android.graphics.BitmapFactory.decodeFile(picturePath, finalBitmapOptions);
|
bitmap = android.graphics.BitmapFactory.decodeFile(picturePath, finalBitmapOptions);
|
||||||
let scaledSizeImage = null;
|
let scaledSizeImage = null;
|
||||||
if (reqHeight > 0 && reqWidth > 0) {
|
if (reqHeight > 0 && reqWidth > 0) {
|
||||||
if (shouldKeepAspectRatio) {
|
if (shouldKeepAspectRatio) {
|
||||||
@ -118,6 +119,10 @@ export var isAvailable = function () {
|
|||||||
|
|
||||||
var calculateInSampleSize = function (imageWidth, imageHeight, reqWidth, reqHeight) {
|
var calculateInSampleSize = function (imageWidth, imageHeight, reqWidth, reqHeight) {
|
||||||
let sampleSize = 1;
|
let sampleSize = 1;
|
||||||
|
let displayWidth = platform.screen.mainScreen.widthDIPs;
|
||||||
|
let displayHeigth = platform.screen.mainScreen.heightDIPs;
|
||||||
|
reqWidth = (reqWidth > 0 && reqWidth < displayWidth) ? reqWidth : displayWidth;
|
||||||
|
reqHeight = (reqHeight > 0 && reqHeight < displayHeigth) ? reqHeight : displayHeigth;
|
||||||
if (imageWidth > reqWidth && imageHeight > reqHeight) {
|
if (imageWidth > reqWidth && imageHeight > reqHeight) {
|
||||||
let halfWidth = imageWidth / 2;
|
let halfWidth = imageWidth / 2;
|
||||||
let halfHeight = imageHeight / 2;
|
let halfHeight = imageHeight / 2;
|
||||||
|
Reference in New Issue
Block a user