将JPEG转换为base64有很好的资源。
我特别感兴趣的是没有解码到bimap,避免任何内存膨胀。我也明白,任何文件都可以通过先将其转换为字节数组编码到Base64中。
因此,如果我们可以直接创建一个JPEG / PNG文件的字节数组,该数组远小于解码的jpeg位图的字节数组,我们可以使用更少的内存占用将其转换为base64。
我遇到的最接近的答案是https://stackoverflow.com/a/10160856/499752
答案 0 :(得分:0)
public void getGalleryDetails(String path) throws FileNotFoundException {
InputStream inputStream = new FileInputStream(path);
byte[] bytes;
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try{
while((bytesRead = inputStream.read(buffer)) != -1){
output.write(buffer, 0, bytesRead);
}
}catch(IOException e){
e.printStackTrace();
}
bytes = output.toByteArray();
encodedImage = Base64.encodeToString(bytes, Base64.DEFAULT);
Log.i("ENCODED", encodedImage);
}
您实际上可以使用此...您可以在其中提供要转换为Base64的文件的路径。对于迟到的帖子感到抱歉...只是说这个帖子。