This commit is contained in:
tiago.kayaya
2021-11-09 10:13:48 +01:00
parent 6d24784991
commit af4524a201
4 changed files with 55 additions and 40 deletions
+5
View File
@@ -2040,6 +2040,11 @@
"resolved": "https://registry.npmjs.org/@capacitor/app/-/app-1.0.5.tgz",
"integrity": "sha512-U0dAw1CAjKyguSRxKDabszsQ4dj679RnxaUZrSHDR5Jnt5x308oQuKXFP++wnMBbw72D02iqjG0a+/Ujye7C9g=="
},
"@capacitor/camera": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@capacitor/camera/-/camera-1.2.0.tgz",
"integrity": "sha512-NAIGWnyHBGQ/dgla/D4KDkAeQ2f3fzw+D+DIkGNH3f1ciX4bXC7lNbDVU67SMOuNt+CmcTJF64q3nVXcpv5JvQ=="
},
"@capacitor/cli": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/@capacitor/cli/-/cli-3.3.0.tgz",
+1
View File
@@ -33,6 +33,7 @@
"@angular/router": "~12.1.2",
"@capacitor/android": "^3.3.0",
"@capacitor/app": "^1.0.5",
"@capacitor/camera": "^1.2.0",
"@capacitor/core": "^3.3.0",
"@capacitor/filesystem": "^1.0.6",
"@capacitor/haptics": "^1.1.3",
@@ -34,7 +34,9 @@
<p>{{capturedImageTitle}}</p>
<p hidden>size</p>
</ion-label>
<ion-icon (click)="clear()" name="close"></ion-icon>
<div (click)="clear()">
<ion-icon name="close"></ion-icon>
</div>
</ion-item>
@@ -9,15 +9,14 @@ import { Image } from 'src/app/models/image';
import { PhotoService } from 'src/app/services/photo.service';
//Capacitor
//Cordova
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { ToastService } from 'src/app/services/toast.service';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { ThemePalette } from '@angular/material/core';
import { formatDate } from 'src/plugin/momentG.js'
import { FileLoaderService } from 'src/app/services/file/file-loader.service';
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
import { ThemeService } from 'src/app/services/theme.service'
import { ThemeService } from 'src/app/services/theme.service';
import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
@Component({
selector: 'app-new-publication',
@@ -59,15 +58,15 @@ export class NewPublicationPage implements OnInit {
guestPicture:any;
capturedImage:any;
capturedImage:any = '';
capturedImageTitle:any;
public photos: any[] = [];
constructor(
private modalController: ModalController,
public photoService: PhotoService,
private navParams: NavParams,
private publications: PublicationsService,
private camera: Camera,
private toastService: ToastService,
private fileLoaderService: FileLoaderService,
private fileToBase64Service: FileToBase64Service,
@@ -81,32 +80,40 @@ export class NewPublicationPage implements OnInit {
ngOnInit() {
this.setTitle();
this.clear();
// this.takePicture();
}
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,
}
async takePicture() {
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Camera
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;
});
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
this.capturedImage = 'data:image/png;base64,'+imageData;
this.capturedImageTitle = new Date().getTime() + '.jpeg';
}, (err) => {
/* console.log(err); */
this.photos.unshift({
filepath: "soon...",
webviewPath: capturedImage.webPath
});
this.capturedImage = await this.convertBlobToBase64(blob);
//console.log(this.capturedImage);
}
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});
laodPicture() {
const input = this.fileLoaderService.createInput({
@@ -125,7 +132,7 @@ export class NewPublicationPage implements OnInit {
}
getPicture() {
/* getPicture() {
const options: CameraOptions = {
quality: 90,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
@@ -143,9 +150,9 @@ export class NewPublicationPage implements OnInit {
this.capturedImage = imageData;
this.capturedImageTitle = new Date().getTime() + '.jpeg';
}, (err) => {
/* console.log(err); */
console.log(err);
});
}
} */
runValidation() {
this.validateFrom = true