【发布时间】:2016-01-31 19:06:12
【问题描述】:
所以我学会了如何通过从 GL_FRONT 读取字节缓冲区来截取我的 LWJGL 显示器的屏幕截图:
public static void takeScreenShot(){
GL11.glReadBuffer(GL11.GL_FRONT);
int width = Display.getDisplayMode().getWidth();
int height = Display.getDisplayMode().getHeight();
int bpp = 4;
ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp);
GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_NSIGNED_BYTE, buffer);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss");
Date date = new Date();
String datetime = dateFormat.format(date);
File file = new File(screenshot_dir + "\\" + datetime + ".png");
String format = "PNG";
BufferedImage image = new BufferedImage(width, height, Bufferedmage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int i = (x + (width * y)) * bpp;
int r = buffer.get(i) & 0xFF;
int g = buffer.get(i + 1) & 0xFF;
int b = buffer.get(i + 2) & 0xFF;
image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | );
}
}
try {
ImageIO.write(image, format, file);
} catch (Exception e) {
e.printStackTrace();
}
}
我假设我可以每秒从前端缓冲区读取大约 60 次(我知道这会显着降低性能)。然后我可以将一定数量的帧写入缓冲区,当它已满时将交换到另一个。缓冲区已满后,可以将其内容附加到文件中。
如何将字节缓冲区格式化为视频中的帧?
谢谢。
【问题讨论】:
标签: java lwjgl video-processing