从2D颜色阵列创建图像

Bar*_*dos 1 java bufferedimage image colors

我有一个名为image [] []的数组,我想创建一个BufferedImage,所以我可以让播放器将它存储在一个文件中.

Jon*_*uis 5

// Initialize Color[][] however you were already doing so.
Color[][] image;

// Initialize BufferedImage, assuming Color[][] is already properly populated.
BufferedImage bufferedImage = new BufferedImage(image.length, image[0].length,
        BufferedImage.TYPE_INT_RGB);

// Set each pixel of the BufferedImage to the color from the Color[][].
for (int x = 0; x < image.length; x++) {
    for (int y = 0; y < image[x].length; y++) {
        bufferedImage.setRGB(x, y, image[x][y].getRGB());
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一种创建(并可能存储)图像的直接方式,如果这是您想要获得的.但是,无论如何这都是无效的.尝试使用更大的图像,你会看到明显的速度差异.