繁体   English   中英

如何将图像的URL转换为base64(IONIC 2)

[英]How can I convert the URL of an image to base64 (IONIC 2)

帮助,如何将图像的URL转换为base64(IONIC 2)

this.camera.getPicture({


sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
  destinationType: this.camera.DestinationType.FILE_URI,
  quality: 100,
  encodingType: this.camera.EncodingType.PNG,
}).then(imageData => {
  console.log('THIS IS THE URI ' + imageData);
  //How do I get the image and convert it to base64 ?
}, error => {
  this.error = JSON.stringify(error);
});

您可以这样做:

this.camera.getPicture({
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
  destinationType: this.camera.DestinationType.DATA_URL,
  quality: 100,
  encodingType: this.camera.EncodingType.PNG,
}).then(imageData => {
  console.log('THIS IS THE Base64' + imageData);
  let base64Image = 'data:image/jpeg;base64,' + imageData;
}, error => {
  this.error = JSON.stringify(error);
});

destinationType支持以下3个选项:

  1. DATA_URL :返回base64编码的字符串。 DATA_URL可能占用大量内存,并导致应用程序崩溃或内存不足错误。 如果可能,请使用FILE_URI或NATIVE_URI
  2. FILE_URI :返回文件uri(适用于Android的content:// media / external / images / media / 2)
  3. NATIVE_URI :返回本地uri(例如,iOS的asset-library:// ...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM