add take picture

This commit is contained in:
Peter Maquiran
2022-01-05 12:54:46 +01:00
parent d84ed799bf
commit e90d444c89
10 changed files with 346 additions and 229 deletions
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams, Platform, LoadingController } from '@ionic/angular';
import { ModalController, NavParams, Platform, LoadingController, PopoverController } from '@ionic/angular';
/* import {Plugins, CameraResultType, CameraSource} from '@capacitor/core'; */
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
@@ -20,6 +20,7 @@ import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera
import { Filesystem, Directory } from '@capacitor/filesystem';
import { NgxImageCompressService } from "ngx-image-compress";
import { PreviewerPage } from 'src/app/modals/previewer/previewer.page';
const IMAGE_DIR = 'stored-images';
interface LocalFile {
@@ -74,9 +75,11 @@ export class NewPublicationPage implements OnInit {
imgResultBeforeCompress: string;
imgResultAfterCompress: string;
convertBlobToBase64Worker;
constructor(
private modalController: ModalController,
private popoverController: PopoverController,
public photoService: PhotoService,
private navParams: NavParams,
private publications: PublicationsService,
@@ -92,6 +95,10 @@ export class NewPublicationPage implements OnInit {
this.publicationType = this.navParams.get('publicationType');
this.folderId = this.navParams.get('folderId');
this.publicationTitle = 'Nova Publicação';
this.convertBlobToBase64Worker = new Worker(new URL('./convertBlobToBase64.worker.js', import.meta.url));
}
ngOnInit() {
@@ -106,7 +113,10 @@ export class NewPublicationPage implements OnInit {
// this.takePicture();
}
imageUrl;
async takePicture() {
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
@@ -114,19 +124,17 @@ export class NewPublicationPage implements OnInit {
source: CameraSource.Camera
});
console.log(capturedImage)
const response = await fetch(capturedImage.webPath!);
this.imageUrl = capturedImage.webPath
const blob = await response.blob();
this.photos.unshift({
filepath: "soon...",
webviewPath: capturedImage.webPath
});
this.capturedImage = await this.convertBlobToBase64(blob);
this.capturedImageTitle = new Date().getTime() + '.jpeg';
//console.log(this.capturedImage);
}
this.convertBlobToBase64Worker.postMessage(blob);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data
}
}
imageSize(image) {
var canvas = document.createElement('canvas');