0

ですから、基本的にはしばらくLWJGLをいじっていたのですが、周りの煩わしさで急に止まりましたglReadPixels()
そして、なぜそれが左下->右上からしか読まないのか。
ですから、私はこれらすべてを理解したので、私自身の質問に答えるためにここにいます。
そして、私の発見が他の誰かに役立つかもしれないことを願っています。

補足として、私が使用しているのは次のとおりです。

glOrtho(0, WIDTH, 0 , HEIGHT, 1, -1);
4

2 に答える 2

3

これが私のスクリーンキャプチャコードで、LWJGLアプリケーションCに実装できます。

//=========================getScreenImage==================================//
    private void screenShot(){
             //Creating an rbg array of total pixels
             int[] pixels = new int[WIDTH * HEIGHT];
             int bindex;
             // allocate space for RBG pixels
             ByteBuffer fb = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3);

             // grab a copy of the current frame contents as RGB
             glReadPixels(0, 0, WIDTH, HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, fb);

             BufferedImage imageIn = new BufferedImage(WIDTH, HEIGHT,BufferedImage.TYPE_INT_RGB);
             // convert RGB data in ByteBuffer to integer array
             for (int i=0; i < pixels.length; i++) {
                 bindex = i * 3;
                 pixels[i] =
                     ((fb.get(bindex) << 16))  +
                     ((fb.get(bindex+1) << 8))  +
                     ((fb.get(bindex+2) << 0));
             }
             //Allocate colored pixel to buffered Image
             imageIn.setRGB(0, 0, WIDTH, HEIGHT, pixels, 0 , WIDTH);

             //Creating the transformation direction (horizontal)
             AffineTransform at =  AffineTransform.getScaleInstance(1, -1);
             at.translate(0, -imageIn.getHeight(null));

             //Applying transformation
             AffineTransformOp opRotated = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
             BufferedImage imageOut = opRotated.filter(imageIn, null);

             try {//Try to screate image, else show exception.
                 ImageIO.write(imageOut, format , fileLoc);
             }
             catch (Exception e) {
                 System.out.println("ScreenShot() exception: " +e);
             }
         }

これがお役に立てば幸いです。
コードに関する質問やコメントについては、必要に応じて質問/提案してください。C:
ハグ、
ローズ。

于 2012-12-11T11:06:58.370 に答える
1

返信が遅くなって申し訳ありませんが、これはまだ解決策を探している人のためのものです。

public static void saveScreenshot() throws Exception {
    System.out.println("Saving screenshot!");
    Rectangle screenRect = new Rectangle(Display.getX(), Display.getY(), Display.getWidth(), Display.getHeight());
    BufferedImage capture = new Robot().createScreenCapture(screenRect);
    ImageIO.write(capture, "png", new File("doc/saved/screenshot.png"));
}
于 2014-06-28T17:31:54.570 に答える