diff --git a/demo-angular/app/app.component.html b/demo-angular/app/app.component.html index b13e6a9..7c4bd42 100644 --- a/demo-angular/app/app.component.html +++ b/demo-angular/app/app.component.html @@ -4,8 +4,5 @@ - - - - + \ No newline at end of file diff --git a/demo-angular/app/app.component.ts b/demo-angular/app/app.component.ts index 62f616e..df5a244 100644 --- a/demo-angular/app/app.component.ts +++ b/demo-angular/app/app.component.ts @@ -2,6 +2,8 @@ import { Component } from '@angular/core'; import { takePicture, requestPermissions } from 'nativescript-camera'; import { ImageSource } from 'tns-core-modules/image-source'; import { ImageAsset } from 'tns-core-modules/image-asset'; +import { layout } from 'tns-core-modules/utils/utils'; +import * as app from "tns-core-modules/application"; @Component({ selector: 'my-app', @@ -12,22 +14,30 @@ export class AppComponent { public cameraImage: ImageAsset; onTakePictureTap(args) { - takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: this.saveToGallery }) - .then((imageAsset) => { - let source = new ImageSource(); - source.fromAsset(imageAsset).then((source) => { - console.log(`Size: ${source.width}x${source.height}`); - }); - this.cameraImage = imageAsset; - }, (error) => { - console.log("Error: " + error); - }); - } - - onRequestPermissionsTap() { requestPermissions().then( - () => console.log('got permissions'), - () => console.log('permissions rejected') + () => { + takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: this.saveToGallery }) + .then((imageAsset: any) => { + this.cameraImage = imageAsset; + + // if you need image source + let source = new ImageSource(); + source.fromAsset(imageAsset).then((source) => { + let width = source.width; + let height = source.height; + if (app.android) { + // the android dimensions are in device pixels + width = layout.toDeviceIndependentPixels(width); + height = layout.toDeviceIndependentPixels(height); + } + + console.log(`Size: ${width}x${height}`); + }); + }, (error) => { + console.log("Error: " + error); + }); + }, + () => alert('permissions rejected') ); } } diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index 4afa9fd..fb46ca3 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -4,6 +4,8 @@ import { View } from 'tns-core-modules/ui/core/view'; import { takePicture, requestPermissions } from "nativescript-camera"; import * as appModule from "tns-core-modules/application"; import * as imageSourceModule from "tns-core-modules/image-source"; +import { layout } from 'tns-core-modules/utils/utils'; +import * as app from "tns-core-modules/application"; import * as trace from "tns-core-modules/trace"; trace.addCategories(trace.categories.Debug); @@ -13,28 +15,36 @@ export function navigatingTo(args: EventData) { let page = args.object; let picturePath = null; - page.bindingContext = fromObject({cameraImage: picturePath, saveToGallery: true}); -} - -export function onRequestPermissionsTap(args: EventData) { - requestPermissions().then( - () => console.log('got permissions'), - () => console.log('permissions rejected') - ); + page.bindingContext = fromObject({ cameraImage: picturePath, saveToGallery: true }); } export function onTakePictureTap(args: EventData) { let page = (args.object).page; let saveToGallery = page.bindingContext.get("saveToGallery"); - takePicture({width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery}). - then((imageAsset) => { - let source = new imageSourceModule.ImageSource(); - source.fromAsset(imageAsset).then((source) => { - console.log(`Size: ${source.width}x${source.height}`); - }); - page.bindingContext.set("cameraImage", imageAsset); + requestPermissions().then( + () => { + takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery }). + then((imageAsset) => { + page.bindingContext.set("cameraImage", imageAsset); + + // if you need image source + let source = new imageSourceModule.ImageSource(); + source.fromAsset(imageAsset).then((source) => { + let width = source.width; + let height = source.height; + if (app.android) { + // the android dimensions are in device pixels + width = layout.toDeviceIndependentPixels(width); + height = layout.toDeviceIndependentPixels(height); + } + + console.log(`Size: ${width}x${height}`); + }); + }, + (err) => { + console.log("Error -> " + err.message); + }); }, - (err) => { - console.log("Error -> " + err.message); - }); + () => alert('permissions rejected') + ); } \ No newline at end of file diff --git a/demo/app/main-page.xml b/demo/app/main-page.xml index 9779999..a99150d 100644 --- a/demo/app/main-page.xml +++ b/demo/app/main-page.xml @@ -5,9 +5,6 @@ - -