nightr/client/Nightr/src/app/services/my-camera-service.ts
2019-04-07 01:38:29 +02:00

35 lines
984 B
TypeScript

import { Injectable } from '@angular/core';
import * as camera from 'nativescript-camera';
import { ImageSource } from 'tns-core-modules/image-source/image-source';
@Injectable({
providedIn: 'root'
})
export class MyCameraService {
constructor() { }
takePicture(): Promise<string> {
var result = new Promise<string>((resolve, reject) => {
camera.requestPermissions().
then(
() => {
camera.takePicture().then(
(imageAsset) => {
var src = new ImageSource();
src.fromAsset(imageAsset).then(
(source) => {
resolve(source.toBase64String("png", 75));
}
);
}
).catch((error) => alert(error.message));
}, () => {
alert("Request rejected");
}
).catch();
});
return result;
}
}