2016-12-15 65 views
1

因此,我使用react-native-signature-capture來捕獲簽名,但我不想在編碼之前減少圖像大小。我用https://github.com/bamlab/react-native-image-resizer調整圖像大小,但現在我不知道如何將其轉換爲base64。我嘗試使用RN的ImageStore,但是我得到了圖像文件路徑的錯誤。見下面的代碼:React Native - 調整圖像大小並將其轉換爲base64

ImageResizer.createResizedImage(encoded.pathName, 200, 100, 'PNG', 80, null, encoded.pathName) 
    .then((resizedImageUrl) => { 
    ImageStore.getBase64ForTag(resizedImageUrl, (data) => { 
     console.log(data); 
    }, (err) => console.log(err)); 
    }) 
    .catch((err) => console.log('failed to resize: ' + err)); 

回答

1

解決了這個一段時間了,忘了把我所做的到現在爲止,我基本上使用的庫上方,react-native-fs來調整和檢索圖像爲Base64:

handleBase64 = async (path) => { 
    const resizedImageUrl = await ImageResizer.createResizedImage(path, 200, 80, 'PNG', 80, 0, RNFS.DocumentDirectoryPath); 
    const base64 = await RNFS.readFile(resizedImageUrl, 'base64'); 
    return base64; 
} 
相關問題