3

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.

何千もの小さな画像を効率的に並べて表示する方法はありますか? 画像が表示されると操作されないため、これは 1 回限りのコストであることに注意してください。

4

3 に答える 3

2

新しい (大きな) 画像の GC (グラフィックス コンテキスト) に直接描画できます。大きな画像が 1 つあると、何千もの小さな画像よりもリソースの使用量が大幅に少なくなります (SWT の各画像は、OS グラフィック オブジェクト ハンドルを保持します)。

あなたが試すことができるのは次のようなものです:

        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
于 2008-11-14T18:07:28.443 に答える
0

おそらく、すべての画像が一度に画面に表示されるわけではありませんか? おそらく、より良い解決策は、画像が表示される (または表示されようとしている) ときにのみ画像を読み込み、画面からスクロールされたときに画像を破棄することです。ユーザーがスムーズに移行できるように、現在のビューポートの両側にいくつかをメモリに保持する必要があることは明らかです。

于 2008-11-13T16:45:20.107 に答える
0

以前、Java アプリケーションを使用してフォトモザイクを作成しましたが、Java イメージング (JAI) ライブラリと SWT を使用して適切なパフォーマンスとメモリ使用量を達成するのは非常に困難であることがわかりました。私たちはあなたが言及したほど多くのイメージを使用していませんでしたが、1 つのルートは Java 以外のユーティリティに依存することでした。特に、ImageMagick コマンドライン ユーティリティを使用してモザイクをつなぎ合わせ、完成したメモリをディスクからロードすることができます。凝ったものにしたい場合は、ImageMagick 用の C++ API もあります。これはメモリ効率が非常に高いです。

于 2008-11-13T16:52:42.743 に答える