Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check how much memory bufferedImage in java uses?

I have a bufferedImage in Java. How do I see how much memory it takes up? Thanks in advance.

like image 717
rustybeanstalk Avatar asked Dec 02 '11 02:12

rustybeanstalk


1 Answers

You can determine how many bytes the image data alone takes up using this:

DataBuffer buff = image.getRaster().getDataBuffer();
int bytes = buff.getSize() * DataBuffer.getDataTypeSize(buff.getDataType()) / 8;

The image itself takes up a bit more space for the color model and other bookkeeping info, but for large images, bytes will be the dominant term.

like image 161
Ted Hopp Avatar answered Oct 01 '22 12:10

Ted Hopp