SWT 图像拼接或平铺/马赛克

发布于 2024-07-08 18:10:50 字数 398 浏览 5 评论 0原文

我有一个 Eclipse RCP 应用程序,它显示大量(10k+)彼此相邻的小图像,就像胶片一样。 对于每个图像,我使用 SWT Image 对象。 这会使用过多的内存和资源。 我正在寻找一种更有效的方法。 我想获取所有这些图像,并通过创建一个具有正确总连接宽度(具有恒定高度)的 ImageData 对象并将它们连接起来,并使用 setPixel() 来连接它们。其余像素。 但是,我无法弄清楚 ImageData 构造函数中使用的 Palette

我还搜索了 SWT 平铺或马赛克功能以从一组图像创建一个图像,但一无所获。

有什么想法可以有效地相邻显示数千个小图像吗? 请注意,一旦显示图像,就不会对其进行操作,因此这是一次性成本。

I have an Eclipse RCP application that displays a lot (10k+) of small images next to each other, like a film strip. For each image, I am using a SWT Image object. This uses an excessive amount of memory and resources. I am looking for a more efficient way. I thought of taking all of these images and concatenating them by creating an ImageData object of the proper total, concatenated width (with a constant height) and using setPixel() for the rest of the pixels. However, the Palette used in the ImageData constructor I can't figure out.

I also searched for SWT tiling or mosaic functionality to create one image from a group of images, but found nothing.

Any ideas how I can display thousands of small images next to each other efficiently? Please note that once the images are displayed, they are not manipulated, so this is a one-time cost.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我一直都在从未离去 2024-07-15 18:10:50

您可以直接在新(大)图像的 GC(图形上下文)上绘制。 拥有一个大图像应该会比数千个小图像占用更少的资源(SWT 中的每个图像都保留一些操作系统图形对象句柄),

您可以尝试如下所示:

        final List<Image> images;
        final Image bigImage = new Image(Display.getCurrent(), combinedWidth, height);
        final GC gc = new GC(bigImage);
        //loop thru all the images while increasing x as necessary:
        int x = 0;
        int y = 0;
        for (Image curImage : images) {
            gc.drawImage(curImage, x, y);
            x += curImage.getBounds().width;
        }
        //very important to dispose GC!!!
                    gc.dispose();
        //now you can use bigImage

You can draw directly on the GC (graphics context) of a new (big) image. Having one big Image should result in much less resource usage than thousands of smaller images (each image in SWT keeps some OS graphics object handle)

What you can try is something like this:

        final List<Image> images;
        final Image bigImage = new Image(Display.getCurrent(), combinedWidth, height);
        final GC gc = new GC(bigImage);
        //loop thru all the images while increasing x as necessary:
        int x = 0;
        int y = 0;
        for (Image curImage : images) {
            gc.drawImage(curImage, x, y);
            x += curImage.getBounds().width;
        }
        //very important to dispose GC!!!
                    gc.dispose();
        //now you can use bigImage
老街孤人 2024-07-15 18:10:50

想必并非所有图像在任何时候都在屏幕上可见? 也许更好的解决方案是仅在图像变得(或即将变得)可见时加载图像,并在它们滚出屏幕时将其丢弃。 显然,您希望在当前视口两侧的内存中保留一些内容,以便为用户提供平滑的过渡。

Presumably not every image is visible on screen at any one time? Perhaps a better solution would be to only load the images when they become (or are about to become) visible, disposing of them when they have been scrolled off the screen. Obviously you'd want to keep a few in memory on either side of the current viewport in order to make a smooth transition for the user.

晨敛清荷 2024-07-15 18:10:50

我以前使用 Java 应用程序创建照片马赛克,发现使用 java 成像 (JAI) 库和 SWT 很难获得足够的性能和内存使用量。 尽管我们没有使用您提到的那么多图像,但一种途径是依赖 java 之外的实用程序。 特别是,您可以使用 ImageMagick 命令行实用程序将马赛克拼接在一起,并从磁盘加载完整的内存。 如果您想要更有趣,还有一个用于 ImageMagick 的 C++ API,它在内存方面非常高效。

I previously worked with a Java application to create photomosaics, and found it very difficult to achieve adequate performance and memory usage using the java imaging (JAI) libraries and SWT. Although we weren't using nearly as many images as you mention, one route was to rely on a utilities outside of java. In particular, you could use ImageMagick command-line utilities to stitch together your mosaic, and the load the completed memory from disk. If you want to get fancy, there is also a C++ API for ImageMagick, which is very efficient in memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文