代码之家  ›  专栏  ›  技术社区  ›  AbhiRam

转换为base64后图像大小增加更多

  •  0
  • AbhiRam  · 技术社区  · 6 年前

    我正在使用 压缩机 用于压缩捕获图像大小的第三方库工作正常,现在大小显示为KB,但当我将此图像转换为 基准64 文件大小变为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;
        }
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Milan Pansuriya    6 年前

    wikipedia ,平均而言,文件应该 它,几乎就是你的数字。