0

画面キャプチャ プログラムのマルチモニター設定で、左上の位置の座標を取得しようとしています。これが私が現在プログラムのために持っているものです:

        int dwidth = 0, dheight = 0; //max dimensions of all monitors
    for (GraphicsDevice gd : GraphicsEnvironment
            .getLocalGraphicsEnvironment().getScreenDevices()) {
        if (gd == GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice()) {
            minx = -width; //My attempt at finding the minimum X value did not work
        }
        dwidth += gd.getDisplayMode().getWidth();
        dheight += gd.getDisplayMode().getHeight();
    }

基本的に、すべてのモニターでプログラムを実行できるようにしたいと考えています。ここで完全なコードを表示するには: https://gist.github.com/fletchto99/5788659

4

2 に答える 2

1

GraphicDeviceから のリストを取得できますGraphicsEnvironment。それぞれGraphicsDeviceが画面を表します。

今、あなたにはいくつかの選択肢があります...

リストを調べて、GraphicsDevicesx/y 座標が最も低いものを見つけるか、それらをすべて「仮想画面」に結合して、そこから上/左座標を抽出するだけです。

例えば...

public static Rectangle getVirtualScreenBounds() {

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice lstGDs[] = ge.getScreenDevices();

    Rectangle bounds = new Rectangle();
    for (GraphicsDevice gd : lstGDs) {

        bounds.add(gd.getDefaultConfiguration().getBounds());

    }

    return bounds;

}
于 2013-06-16T05:22:48.197 に答える
1

Java では、グラフィック ライブラリの座標系は画面の左上部分から始まります。したがって、コードは常に単に次のように記述することと同等である必要があります: 0, 0.

于 2013-06-15T19:00:04.723 に答える