Html 拍摄的照片不';镜头事件后t消失
我正在为我的应用程序安装摄像头。照相机在工作。它打开了,我也可以拍照。但当我按下“使用图片”时,问题出现了,然后图像应该出现在卡上,但只有一张没有图片的空卡。你有什么想法吗?我上传下面的代码 HTMLHtml 拍摄的照片不';镜头事件后t消失,html,angular,typescript,ionic-framework,Html,Angular,Typescript,Ionic Framework,我正在为我的应用程序安装摄像头。照相机在工作。它打开了,我也可以拍照。但当我按下“使用图片”时,问题出现了,然后图像应该出现在卡上,但只有一张没有图片的空卡。你有什么想法吗?我上传下面的代码 HTML 在ts文件中有一个photos数组,您正在其中推送图像对象。您只需要使用*ngFor循环遍历它 <ion-card *ngFor="let photo of photos"> <img [src]="photo"> </ion-card> 没有使
在ts文件中有一个
photos
数组,您正在其中推送图像对象。您只需要使用*ngFor
循环遍历它
<ion-card *ngFor="let photo of photos">
<img [src]="photo">
</ion-card>
没有使用照片数组…那么我必须写什么呢?你想显示多张照片吗?
这就是你要找的吗?好的,现在可以了:)
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
/**
* Generated class for the PostPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-post',
templateUrl: 'post.html',
})
export class PostPage {
public photos: any;
public base64Image: string;
constructor(public navCtrl: NavController, private camera: Camera) {
}
ngOnInit(){
this.photos = [];
}
ionViewDidEnter(){ //Damit Kamera automatisch öffent
const options: CameraOptions = {
quality: 50,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
this.base64Image = 'data:image/jpeg;base64,' + imageData;
this.photos.push(this.base64Image);
this.photos.reverse();
}, (err) => {
// Handle error
});
}
}
<ion-card *ngFor="let photo of photos">
<img [src]="photo">
</ion-card>