我正在寻找将图像从 GPU 下载到文件的最快方法,以便稍后在同一个应用程序中加载(因此不一定是 PNG,例如)。
但是我注意到,当我直接使用 DeflaterStream 时,它比带有 DeflaterStream 的 ImageIO 慢得多(因此使用 ImageIO.write(deflaterstream) )。
难道我做错了什么?还是 ImageIO 只是经过高度优化/比最快的 GZIP 压缩更好?
glBindTexture(GL_TEXTURE_2D, textureId);
int bpp = 4; // Assuming a 32-bit display with a byte each for red, green, blue, and alpha.
ByteBuffer buffer = BufferUtils.createByteBuffer(SAVE_WIDTH * SAVE_HEIGHT * bpp);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA8, GL_UNSIGNED_BYTE, buffer );
// File file = new File("saves/s-" + layer + ".png"); // The file to save to.
String format = "png"; // Example: "PNG" or "JPG"
// BufferedImage image = new BufferedImage(SAVE_WIDTH, SAVE_HEIGHT, BufferedImage.TYPE_INT_ARGB);
try {
FileOutputStream bOut = new FileOutputStream("saves/p-"+ layer + ".gz");
DeflaterOutputStream gzipOut = new DeflaterOutputStream (bOut, new Deflater(Deflater.BEST_SPEED));
//buffer.flip();
System.out.println("Bytes remaining " + buffer.remaining());
while (buffer.hasRemaining()) gzipOut.write(buffer.get());
gzipOut.close();
bOut.close();
} catch (IOException ex) {
Logger.getLogger(SaveStateManager.class.getName()).log(Level.SEVERE, null, ex);
}