将大量图像显示到网格中 [英] Display a big number of images into a grid

查看:73
本文介绍了将大量图像显示到网格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想在其中显示许多图像组件.其中的每一项将是一个custom jcomponent,该图像将在BufferedImage对象中具有图像,以便使用paintcomponents(Graphics g)重写的方法进行绘制.我还将对网格使用JPanel并使用gridlayoutflowlayout放置自定义图像jcomponents,网格的布局也将位于JscrollPane内部.

我的问题是,当我必须放入网格中的图像数量变大时,会发生什么.使用jscrollpane时,要绘制的图像数量将减少,就像20-30个组件一样,但是插入到网格中的每个组件都会有一个BufferedImage对象来保留相应的图像.这对性能和内存消耗有害吗?可以使用一些模式吗?例如,如果我使用一个主要参考点将图像从磁盘加载到bufferedimage,并且根据scrollpane的哪个矩形,则用户释放一些缓冲的图像,这些图像从scrollpane的当前位置放到网格中c8>?

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?

谢谢.

推荐答案

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

You're going to have to prototype the essential variables and profile the results. Then compare those results to the capabilities available on your lowest common denominator target platform. An sscce is invaluable. This one, for example, will let you easily vary N, the number of images.

此处.

在注释中注明:为了节省内存,请考虑使用 LRU缓存.

Noted in comment: To conserve memory, consider an LRU cache.

这篇关于将大量图像显示到网格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆