简体   繁体   English

java.awt.Image对象使用的内存

[英]Memory used by java.awt.Image object

How can I get the memory used by an instance of the class java.awt.Image ? 如何获取类java.awt.Image的实例使用的内存?

There are other similar questions , but is there an easier way of calculating the memory used by an object of a specific class ( java.awt.Image )? 还有其他类似的问题 ,但是有没有更简单的方法来计算特定类的对象( java.awt.Image )使用的内存?

I would prefer to get the amount of bytes used programatically and not via a profiler so that I can use it to calculate memory statistics inside my application. 我更希望以编程方式而不是通过探查器来获取字节数,以便可以使用它来计算应用程序内部的内存统计信息。

Thanks in advance. 提前致谢。

This will vary between implementations of java.awt.Image , because it depends how the subclass decides to store the data. 这在java.awt.Image实现之间会有所不同,因为它取决于子类决定存储数据的方式。

But for BufferedImage, img.getData().getDataBuffer(); 但是对于BufferedImage,请img.getData().getDataBuffer(); will give you the raw DataBuffer that stores the image. 将为您提供存储图像的原始DataBuffer。 You can then use getDataType() and getSize() to determine the capacity of the data buffer. 然后,您可以使用getDataType()getSize()来确定数据缓冲区的容量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM