2021-09-13 12:37:58 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { FileLoaderService } from '../file/file-loader.service';
|
|
|
|
|
import { FileToBase64Service } from '../file/file-to-base64.service';
|
2021-09-14 15:57:24 +01:00
|
|
|
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
|
2021-09-14 10:30:13 +01:00
|
|
|
//Cordova
|
|
|
|
|
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
|
2021-09-13 12:37:58 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class FileService {
|
|
|
|
|
|
|
|
|
|
capturedImage:any;
|
|
|
|
|
capturedImageTitle:any;
|
|
|
|
|
|
|
|
|
|
constructor(
|
2021-09-14 10:30:13 +01:00
|
|
|
private camera: Camera,
|
2021-09-13 12:37:58 +01:00
|
|
|
private fileLoaderService: FileLoaderService,
|
|
|
|
|
private fileToBase64Service: FileToBase64Service,
|
2021-09-14 15:57:24 +01:00
|
|
|
private iab: InAppBrowser,
|
2021-09-13 12:37:58 +01:00
|
|
|
) { }
|
|
|
|
|
|
2021-09-14 10:30:13 +01:00
|
|
|
takePicture() {
|
|
|
|
|
const options: CameraOptions = {
|
|
|
|
|
quality: 50,
|
|
|
|
|
destinationType: this.camera.DestinationType.DATA_URL,
|
|
|
|
|
encodingType: this.camera.EncodingType.JPEG,
|
|
|
|
|
mediaType: this.camera.MediaType.PICTURE,
|
|
|
|
|
targetWidth: 720,
|
|
|
|
|
targetHeight: 720,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.camera.getPicture(options).then((imageData) => {
|
|
|
|
|
// imageData is either a base64 encoded string or a file URI
|
|
|
|
|
// If it's base64 (DATA_URL): m
|
|
|
|
|
//let base64Image = 'data:image/jpeg;base64,' + imageData;
|
|
|
|
|
|
|
|
|
|
this.capturedImage = 'data:image/png;base64,'+imageData;
|
|
|
|
|
this.capturedImageTitle = new Date().getTime() + '.jpeg';
|
|
|
|
|
}, (err) => {
|
|
|
|
|
/* console.log(err); */
|
|
|
|
|
});
|
|
|
|
|
let data = {
|
|
|
|
|
image:this.capturedImage,
|
|
|
|
|
name: this.capturedImageTitle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 12:37:58 +01:00
|
|
|
loadPicture() {
|
|
|
|
|
const input = this.fileLoaderService.createInput({
|
|
|
|
|
accept: ['image/apng', 'image/jpeg', 'image/png']
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
input.onchange = async () => {
|
|
|
|
|
const file = this.fileLoaderService.getFirstFile(input)
|
|
|
|
|
|
|
|
|
|
console.log(file);
|
|
|
|
|
|
|
|
|
|
const imageData = await this.fileToBase64Service.convert(file)
|
|
|
|
|
this.capturedImage = imageData;
|
|
|
|
|
this.capturedImageTitle = file.name;
|
|
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
|
image:this.capturedImage,
|
|
|
|
|
name: this.capturedImageTitle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
};
|
|
|
|
|
}
|
2021-09-14 15:57:24 +01:00
|
|
|
|
|
|
|
|
viewDocumentByUrl(url) {
|
|
|
|
|
const browser = this.iab.create(url,"_blank");
|
|
|
|
|
browser.show();
|
|
|
|
|
}
|
2021-09-13 12:37:58 +01:00
|
|
|
}
|