OutOfMemory when creating Base64 string in java?

后端 未结 4 1744
清酒与你
清酒与你 2021-01-24 07:48

I used ostermillerutils library to create base64 string but I get OutOfMemory error if the image is heavy. If the image I try to convert is a simple image, the code is working f

4条回答
  •  情书的邮戳
    2021-01-24 08:00

    It sounds like the problem is that you're having to manipulate too much data in memory when you read the entire image. One fix would be to increase the Java heap size until you have enough memory, but that would just be avoiding the problem rather than solving it.

    A better option would be to look at a streaming implementation of a Base64 encoder. This would mean you're only working on a subset of the image at any time. I believe that Base64OutputStream from Apache Commons would do the job for you.

提交回复
热议问题