gpt4 book ai didi

java - 在 java 中读取和存储 .bmp 文件

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

我正在尝试读取名为 circle1.bmp 的 .bmp 文件。它位于我已导入到以下文件中的包中。

到目前为止,我有以下代码,但是当我运行以下代码时,我得到:

javax.imageio.llOException: 无法读取输入文件!

public void setUp() throws IOException
{
BufferedImage image = ImageIO.read(new File("circle1.bmp"));
byte[][] greenInputData = new byte[30][40];

for (int x = 0; x < inputData.length; x++)
{
for (int y = 0; y < inputData[x].length; y++)
{
int color = image.getRGB(x, y);
//alpha[x][y] = (byte)(color>>24);
//red[x][y] = (byte)(color>>16);
greenInputData[x][y] = (byte)(color>>8);
//blue[x][y] = (byte)(color);
}
}
this.inputData = greenInputData;

System.out.println(this.inputData);
}

最佳答案

你应该尝试类似的东西

image = ImageIO.read(getClass().getResourceAsStream("path/to/your/file.bmp"));

关于java - 在 java 中读取和存储 .bmp 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13110159/

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