@@ -4,6 +4,8 @@ import { View } from 'tns-core-modules/ui/core/view';
44import { takePicture , requestPermissions } from "nativescript-camera" ;
55import * as appModule from "tns-core-modules/application" ;
66import * as imageSourceModule from "tns-core-modules/image-source" ;
7+ import { layout } from 'tns-core-modules/utils/utils' ;
8+ import * as app from "tns-core-modules/application" ;
79
810import * as trace from "tns-core-modules/trace" ;
911trace . addCategories ( trace . categories . Debug ) ;
@@ -13,28 +15,36 @@ export function navigatingTo(args: EventData) {
1315 let page = < Page > args . object ;
1416 let picturePath = null ;
1517
16- page . bindingContext = fromObject ( { cameraImage : picturePath , saveToGallery : true } ) ;
17- }
18-
19- export function onRequestPermissionsTap ( args : EventData ) {
20- requestPermissions ( ) . then (
21- ( ) => console . log ( 'got permissions' ) ,
22- ( ) => console . log ( 'permissions rejected' )
23- ) ;
18+ page . bindingContext = fromObject ( { cameraImage : picturePath , saveToGallery : true } ) ;
2419}
2520
2621export function onTakePictureTap ( args : EventData ) {
2722 let page = < Page > ( < View > args . object ) . page ;
2823 let saveToGallery = page . bindingContext . get ( "saveToGallery" ) ;
29- takePicture ( { width : 180 , height : 180 , keepAspectRatio : true , saveToGallery : saveToGallery } ) .
30- then ( ( imageAsset ) => {
31- let source = new imageSourceModule . ImageSource ( ) ;
32- source . fromAsset ( imageAsset ) . then ( ( source ) => {
33- console . log ( `Size: ${ source . width } x${ source . height } ` ) ;
34- } ) ;
35- page . bindingContext . set ( "cameraImage" , imageAsset ) ;
24+ requestPermissions ( ) . then (
25+ ( ) => {
26+ takePicture ( { width : 180 , height : 180 , keepAspectRatio : true , saveToGallery : saveToGallery } ) .
27+ then ( ( imageAsset ) => {
28+ page . bindingContext . set ( "cameraImage" , imageAsset ) ;
29+
30+ // if you need image source
31+ let source = new imageSourceModule . ImageSource ( ) ;
32+ source . fromAsset ( imageAsset ) . then ( ( source ) => {
33+ let width = source . width ;
34+ let height = source . height ;
35+ if ( app . android ) {
36+ // the android dimensions are in device pixels
37+ width = layout . toDeviceIndependentPixels ( width ) ;
38+ height = layout . toDeviceIndependentPixels ( height ) ;
39+ }
40+
41+ console . log ( `Size: ${ width } x${ height } ` ) ;
42+ } ) ;
43+ } ,
44+ ( err ) => {
45+ console . log ( "Error -> " + err . message ) ;
46+ } ) ;
3647 } ,
37- ( err ) => {
38- console . log ( "Error -> " + err . message ) ;
39- } ) ;
48+ ( ) => alert ( 'permissions rejected' )
49+ ) ;
4050}
0 commit comments