gpt4 book ai didi

java - 从 2D 颜色阵列创建图像

转载 作者:行者123 更新时间:2023-11-29 08:02:46 25 4
gpt4 key购买 nike

我有一个名为 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());
}
}

这是一种创建(并可能存储)图像的直接方法,如果这正是您想要达到的目的。然而,这无论如何都不是有效的。尝试使用更大的图像,您会看到明显的速度差异。

关于java - 从 2D 颜色阵列创建图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13391404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com