JScrollPane中的java巨大的BufferedImage [英] java huge BufferedImage in JScrollPane

查看:113
本文介绍了JScrollPane中的java巨大的BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在JScrollPane派生的类中放入一个巨大的图像(BufferedImage以访问颜色等).没什么难的,直到那里.

I need to fit a huge image (BufferedImage to access colors etc) into a JScrollPane derived class. Nothing very hard until there.

图像是对A3材料样本的JPG扫描,其大小为13030x20840像素,24位,并且在磁盘上的重量为12MB->在RAM中约为800MB.

The image is a JPG scan of an A3 sample of material, its size is 13030x20840 pixels, 24bits, and weights 12MB on disk -> about 800MB in RAM.

我将BufferedImage嵌入到Jpanel中,该面板位于Scrollpane的视图中.

I embedded the BufferedImage into a Jpanel, which lies as the Scrollpane's view.

当我尝试滚动/拖动我的图像时,它需要几秒钟的响应时间,所以不是很方便.

When I try to scroll/drag my image, it takes seconds to respond, so it is not very handy.

我需要您的帮助,以便知道我该怎么做才能使滚动窗格的滚动和图像拖动尽可能平滑和反应性,但是我很容易发现使用这种图像是不可能的.

I need your help in order to know what I should do to render the scrollpane's scrolling and the image dragging as smooth and reactive as possible, but I easily figure out that with such an image it could be impossible.

我尝试了很多选项,例如双缓冲等,但是我对Swing还是很陌生,那么很有可能我错过了一些简单的解决方案.

I tried many options, such as double buffering, etc. but I'm quite new to Swing, then it is greatly possible I missed some simple solution.

如果需要通过其他方式更改BufferedImage,我愿意接受任何解决方案.

If there is a need to change the BufferedImage by something else, or whatever, I'm receptive to any solution.

推荐答案

因此,我们有一个13,030 x 20,840像素的大图像.

So, we have a large 13,030 x 20,840 pixel image.

如果将图像拆分为256 x 256像素的图块,则会得到一个图块集,该图块集为51个图块和82个图块向下.行和列中的最后一个图块将是部分图像,因为256像素不能均匀地分布到13,030和20,840中.

if we break this image into 256 x 256 pixel tiles, we get a tile set that's 51 tiles across and 82 tiles down. The last tiles in the rows and columns will be partial images, since 256 doesn't go evenly into 13,030 and 20,840.

假设我们的显示窗口为400 X 400像素.我们还假设是从大图像的左上角开始的.

Let's assume our display window is 400 X 400 pixels. Let's also assume were starting in the upper left hand corner of the large image.

我们拍摄并制作一个3 x 3的图块缓冲图像.这将是768 x 768像素,允许足够的重叠以平滑滚动.我们从第一行获取前3个图块,从第二行获取前3个图块,从第三行获取前3个图块,以制作3 x 3图块缓冲的图像.

We take and make a 3 x 3 tile buffered image. This would be 768 x 768 pixels, which allows enough overlap for smooth scrolling. We take the first 3 tiles from the first row, the first 3 tiles from the second row, and the first 3 tiles from the third row to make our 3 x 3 tile buffered image.

现在,当我们在JScrollPane上设置水平和垂直滚动时,我们必须将水平滚动的最大值设置为13030,将垂直滚动的最大值设置为20840.这样一来,用户就可以动态地意识到自己正在滚动大图像.

Now, when we set up the horizontal and vertical scroll on the JScrollPane, we have to set the maximum value on the horizontal scroll to 13,030 and the maximum value on the vertical scroll to 20,840. This is so the user is kinetically aware that he is scrolling a large image.

好吧,我们显示3 x 3的图块缓冲图像.用户向右滚动以查看更多图像.用户已滚动256个像素.

Ok, we display the 3 x 3 tile buffered image. The user scrolls to the right to see more images. The user has scrolled 256 pixels.

应用程序现在必须构建一个新的3 x 3切片缓冲图像.我们从第一行,第二行和第三行获取第二到第四块磁贴.我们显示此新的缓冲图像.对用户而言,它看起来像一张巨大的图像.对于该应用程序,显示了一系列小的3 x 3磁贴缓冲图像.

The application now has to build a new 3 x 3 tile buffered image. We take the 2nd through 4th tiles from the first row, second row, and third row. We display this new buffered image. To the user, it looks like one huge image. To the application, a series of small 3 x 3 tile buffered images are displayed.

mKorbel已经创建了一些代码即可动态生成并显示这些较小的缓冲图像.

mKorbel has already created some code which builds and displays these smaller buffered images on the fly.

要处理缩放,可以在Java应用程序外部调整大图像的大小,并创建多个图块集.这使Java应用程序代码更加复杂,但是比尝试在Java应用程序中调整较小的缓冲图像的大小要快得多.

To deal with zooming, you can resize the large image outside of the Java application and create more than one tile set. This makes the Java application code more complicated, but much faster than trying to resize the smaller buffered images in the Java application.

这篇关于JScrollPane中的java巨大的BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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