繁体   English   中英

从2D彩色阵列创建图像

[英]Create image from 2D Color Array

我有一个名为image [] []的数组,我想以此创建一个BufferedImage,以便让播放器将其存储在文件中。

// 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());
    }
}

如果您要尝试的话,这是创建(并可能存储)图像的直接方法。 但是,这绝不是有效的方法。 尝试放大图像,您会发现明显的速度差异。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM