开发者

How to write an Image without running out of memory in Java?

final BufferedImage img = new BufferedImage(3500, 2480, BufferedImage.TYPE_BYTE_INDEXED);
final Graphics2D g2D = img.createGraphics();
g2D.setBackground(Color.white);
g2D.clearRect(0, 0, width, height);

(full code in this question).

This code results in a Java Heap Space exception although I've set the jvm attribute to 3GB. Could that be the problem?

Anyway isn't it possible t开发者_JAVA百科o draw the image with less memory? I'm after an A4-size BMP for printing, only with text. Most of the time it's black-and-white only, while at some times I'll need to use blue, pink, and gray too.


There is something very fishy about the facts stated in your question. Unless I'm mistakened, that BufferedImage uses 1 byte per pixel, and therefore 3500 x 2480 bytes ... around 10Mbytes. But you claim to have set the heap size to 3Gbytes.

What JVM options did you actually use?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜