【问题标题】:Image size increased more after convert to Base64转换为 Base64 后图像大小增加更多
【发布时间】:2018-06-22 04:48:03
【问题描述】:

我正在使用 Compressor 第三方库来压缩捕获的图像大小,它工作正常,现在大小显示 KB,但是当我将此图像转换为 BASE64 文件大小变为6MB 或更大的大小显示我的代码如下,有人可以帮助我吗?我应该怎么做才能解决这个问题

代码:

 File file= new Compressor(this).compressToFile(f);
   String base64File  = getBase64StringFile(file);

     // Converting File to Base64.encode String type using Method
    public static String getBase64StringFile(File f) {

        InputStream inputStream = null;
        String encodedFile= "", lastVal;
        try {
            inputStream = new FileInputStream(f.getAbsolutePath());

            byte[] buffer = new byte[10240];//specify the size to allow
            int bytesRead;
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            Base64OutputStream output64 = new Base64OutputStream(output, Base64.DEFAULT);

            while ((bytesRead = inputStream.read(buffer)) != -1) {
                output64.write(buffer, 0, bytesRead);
            }
            output64.close();
            encodedFile =  output.toString();
        }
        catch (FileNotFoundException e1 ) {
            e1.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        lastVal = encodedFile;
        return lastVal;
    }

【问题讨论】:

    标签: android base64


    【解决方案1】:

    您可以使用 FFMPEG 等其他一些 Compressor 工具解决此问题。

    Base64 总是会增加您的文件大小

    Base64 通常用于需要在并非真正为二进制设计的系统中传输的二进制数据。根据您正在做的事情,您甚至可能不需要对其进行编码。根据wikipedia,平均而言,当您使用 base64 编码时,文件预计会增长约 37%,这几乎与您的数字完全相同。

    【讨论】:

    • FFMPEG Base64 没有增加实际文件大小?
    • @AbhiRam 使用 ffmpeg,而不是 Base64
    • @AbhiRam 我正在编辑我的答案 ffmpge 和 base64 两者都是不同的。工具
    • 或者让你的后端团队将其 Base64 更改为 multipart
    • @AbhiRam 是的,它会减少你的代码和文件大小
    猜你喜欢
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多