@@ -4,6 +4,8 @@ import { View } from 'tns-core-modules/ui/core/view';
4
4
import { takePicture , requestPermissions } from "nativescript-camera" ;
5
5
import * as appModule from "tns-core-modules/application" ;
6
6
import * 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" ;
7
9
8
10
import * as trace from "tns-core-modules/trace" ;
9
11
trace . addCategories ( trace . categories . Debug ) ;
@@ -13,28 +15,36 @@ export function navigatingTo(args: EventData) {
13
15
let page = < Page > args . object ;
14
16
let picturePath = null ;
15
17
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 } ) ;
24
19
}
25
20
26
21
export function onTakePictureTap ( args : EventData ) {
27
22
let page = < Page > ( < View > args . object ) . page ;
28
23
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
+ } ) ;
36
47
} ,
37
- ( err ) => {
38
- console . log ( "Error -> " + err . message ) ;
39
- } ) ;
48
+ ( ) => alert ( 'permissions rejected' )
49
+ ) ;
40
50
}
0 commit comments