1

I have an application, in which I want to displaying a number of image components. Each item of this will be a custom jcomponent which will has the image in a BufferedImage object to draw it in paintcomponents(Graphics g) overrided method. I will also use a JPanel for the grid with a gridlayout or flowlayout for place the custom image jcomponents, also the grid's layout will be inside an JscrollPane.

My question is what happens, when the number of the images I must to put into the grid will become big. With use of the jscrollpane, the number of the components so the number of the images must be draw will be smaller like 20-30 components, but each component inserted into the grid will have an object of BufferedImage to keep the corresponding image. This is bad for the perfomance and the memory consuption? May can use some pattern? for example if I use a main point of reference to load the images from disk to bufferedimage and depending of which rectangle of the scrollpane the user then release some bufferedimage where they putted away in the grid from the current position of the jscrollpane?

Thank you.

4

2 回答 2

2
  1. 线程加载图像,以便 UI 不会因加载而延迟
  2. 缩放图像,可能适合面板的大小,浪费内存没有意义
于 2012-08-01T20:01:59.250 回答
2

您将不得不对基本变量进行原型设计并分析结果。然后将这些结果与您的最低公分母目标平台上可用的功能进行比较。sscce无价的。例如,这一个会让你轻松改变N图像的数量。

这里提到了一些视图替代方案。

注释中指出:为了节省内存,请考虑使用LRU 缓存

于 2012-08-01T19:01:18.247 回答