离子保存base64字符串作为galary中的图像

时间:2018-01-21 15:54:08

标签: cordova ionic2 ionic3 ionic-native

   ngOnInit(){

        this.photos=[];
      }

      takePhotos(){

        const options: CameraOptions = {

          quality: 30,
          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
        });
      }

带有相机插件img的离子应用程序点击并显示在屏幕上,如何将这个base64字符串保存为galary中的图像,并获取每个img保存的路径?任何机构能用一个简单的例子来描述吗?

1 个答案:

答案 0 :(得分:0)

  const options: CameraOptions = {
  quality: 30,
  destinationType: this.camera.DestinationType.DATA_URL,   
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE,
  saveToPhotoAlbum : true
}

只需添加此行saveToPhotoAlbum:true即可开始以节奏方式保存图片。