2017-08-10 19 views
0

幫助,我怎樣才能圖像的URL轉換爲Base64(離子2)如何將圖片的URL轉換爲Base64(離子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); 
}); 
+0

解決方案是否適合您? –

回答

0

你可以這樣說:

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(內容://媒體/外部/圖像/媒體/ 2用於Android系統)
  3. NATIVE_URI:返回本地URI(如資產庫。: // ...用於iOS)
相關問題