【问题标题】:Taken picture doesn't is disappeared after camera event相机事件后拍摄的照片不会消失
【发布时间】:2018-08-04 09:16:33
【问题描述】:

我现在正在为我的应用程序实现一个摄像头。相机正在工作。它打开了,我也可以拍照。但是当我按“使用图片”时出现问题,然后图像应该出现在卡上,但只有一张没有图片的空卡。你有什么想法?我上传下面的代码。

HTML

<ion-content padding> 
 <ion-card>
  <img [src]="photo">
 </ion-card>
</ion-content>

打字稿

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
});
  }
}

【问题讨论】:

  • &lt;img [src]="photo"&gt; 没有使用照片数组...
  • 那我要写什么呢?
  • 要显示多张图片?
  • &lt;ion-card *ngFor="let photo of photos"&gt; &lt;img [src]="photo"&gt; &lt;/ion-card&gt; 这就是您要找的东西吗?
  • 好的,现在可以了:)

标签: html angular typescript ionic-framework


【解决方案1】:

您在推送图像对象的 ts 文件中有一个 photos 数组。您只需要使用*ngFor 循环遍历它。

<ion-card *ngFor="let photo of photos"> 
    <img [src]="photo"> 
</ion-card>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-29
    相关资源
    最近更新 更多