gpt4 book ai didi

java - 表达式的类型必须是数组类型但它解析为 BufferedImage

转载 作者:行者123 更新时间:2023-12-02 10:41:39 26 4
gpt4 key购买 nike

这真的很奇怪,错误在 textures[x] .

The type of the expression must be an array type but it resolved to BufferedImage

What is wrong with the code here?

static BufferedImage textures[][] = new BufferedImage[20][20];

public static void loadTextures()
{
try
{
//Loads The Image
BufferedImage textures = ImageIO.read(new URL("textures.png"));

for (int x = 0; x < 1280; x += 1)
{
for (int y = 0; y < 1280; y += 1)
{
textures[x][y] = textures.getSubimage(x*64, y*64, 64, 64);
}
}

} catch (Exception e)
{
e.printStackTrace();
}
}

最佳答案

您正在为计划将图像分割成单个元素的数组重复使用您为数组提供的名称。你应该给它一个不同的名字以使其工作:

BufferedImage fullImage = ImageIO.read(new URL("textures.png"));

for (int x = 0; x < 1280; x += 1) {
for (int y = 0; y < 1280; y += 1) {
textures[x][y] = fullImage.getSubimage(x*64, y*64, 64, 64);
}
}

关于java - 表达式的类型必须是数组类型但它解析为 BufferedImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13504225/

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