This commit is contained in:
tiago.kayaya
2021-11-09 10:39:14 +01:00
parent dbaf562659
commit a1703add7d
2 changed files with 43 additions and 62 deletions
@@ -43,17 +43,6 @@
</div> </div>
<div class="ion-item-container-no-border">
<ion-label (click)="laodPicture()" class="cursor-pointer">
<div class="attach-icon">
<ion-icon src="assets/images/icons-add-photos.svg"></ion-icon>
</div>
<div class="attach-document cursor-pointer">
<ion-label>Anexar Fotografia</ion-label>
</div>
</ion-label>
</div>
<div *ngIf="capturedImage != ''" class="ion-item-container-no-border"> <div *ngIf="capturedImage != ''" class="ion-item-container-no-border">
<ion-label class="attached-title">Fotografia Anexada</ion-label> <ion-label class="attached-title">Fotografia Anexada</ion-label>
<ion-item lines="none"> <ion-item lines="none">
@@ -65,7 +54,9 @@
<p>{{capturedImageTitle}}</p> <p>{{capturedImageTitle}}</p>
<p hidden>size</p> <p hidden>size</p>
</ion-label> </ion-label>
<ion-icon (click)="clear()" name="close"></ion-icon> <button class="btn-no-color" (click)="clear()">
<ion-icon name="close"></ion-icon>
</button>
</ion-item> </ion-item>
</div> </div>
@@ -82,7 +73,7 @@
</div> </div>
<div class="ion-item-container-no-border hide-desktop"> <div class="ion-item-container-no-border hide-desktop">
<ion-label (click)="getPicture()" class="cursor-pointer"> <ion-label (click)="laodPicture()" class="cursor-pointer">
<div class="attach-icon"> <div class="attach-icon">
<ion-icon src="assets/images/icons-add-photos.svg"></ion-icon> <ion-icon src="assets/images/icons-add-photos.svg"></ion-icon>
</div> </div>
@@ -4,11 +4,11 @@ import { PublicationsService } from 'src/app/services/publications.service';
import { Publication } from 'src/app/models/publication'; import { Publication } from 'src/app/models/publication';
import { Image } from 'src/app/models/image'; import { Image } from 'src/app/models/image';
import { PhotoService } from 'src/app/services/photo.service'; import { PhotoService } from 'src/app/services/photo.service';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { ToastService } from 'src/app/services/toast.service'; import { ToastService } from 'src/app/services/toast.service';
import { FormControl, FormGroup, Validators } from '@angular/forms'; import { FormControl, FormGroup, Validators } from '@angular/forms';
import { FileLoaderService } from 'src/app/services/file/file-loader.service' import { FileLoaderService } from 'src/app/services/file/file-loader.service'
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
@Component({ @Component({
selector: 'app-new-publication', selector: 'app-new-publication',
templateUrl: './new-publication.page.html', templateUrl: './new-publication.page.html',
@@ -41,13 +41,13 @@ export class NewPublicationPage implements OnInit {
guestPicture:any; guestPicture:any;
capturedImage:any; capturedImage:any = '';
capturedImageTitle:any; capturedImageTitle:any;
photos: any[] = [];
constructor( constructor(
public photoService: PhotoService, public photoService: PhotoService,
private publications: PublicationsService, private publications: PublicationsService,
private camera: Camera,
private toastService: ToastService, private toastService: ToastService,
private fileLoaderService: FileLoaderService, private fileLoaderService: FileLoaderService,
private fileToBase64Service: FileToBase64Service private fileToBase64Service: FileToBase64Service
@@ -60,8 +60,8 @@ export class NewPublicationPage implements OnInit {
this.getPublicationDetail(); this.getPublicationDetail();
} }
this.setTitle(); this.setTitle();
this.clear(); //this.clear();
this.takePicture(); //this.takePicture();
} }
getPublicationDetail() { getPublicationDetail() {
@@ -88,24 +88,36 @@ export class NewPublicationPage implements OnInit {
} }
takePicture() { async takePicture() {
const options: CameraOptions = { const capturedImage = await Camera.getPhoto({
quality: 90, quality: 90,
destinationType: this.camera.DestinationType.DATA_URL, // allowEditing: true,
encodingType: this.camera.EncodingType.JPEG, resultType: CameraResultType.Uri,
mediaType: this.camera.MediaType.PICTURE, source: CameraSource.Camera
targetWidth: 720,
targetHeight: 720, });
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
this.photos.unshift({
filepath: "soon...",
webviewPath: capturedImage.webPath
});
this.capturedImage = await this.convertBlobToBase64(blob);
//console.log(this.capturedImage);
} }
this.camera.getPicture(options).then((imageData) => { convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
this.capturedImage = imageData; reader.onerror = reject;
this.capturedImageTitle = new Date().getTime() + '.jpeg'; reader.onload = () => {
}, (err) => { resolve(reader.result);
console.log(err); };
reader.readAsDataURL(blob);
}); });
}
laodPicture() { laodPicture() {
const input = this.fileLoaderService.createInput({ const input = this.fileLoaderService.createInput({
@@ -270,28 +282,6 @@ export class NewPublicationPage implements OnInit {
} }
} }
getPicture() {
const options: CameraOptions = {
quality: 90,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
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):
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.capturedImage = imageData;
this.capturedImageTitle = new Date().getTime() + '.jpeg';
}, (err) => {
/* console.log(err); */
});
}
close(){ close(){
this.goBack(); this.goBack();
} }