我有一个缓冲图像数组,我尝试使用for循环将图像显示到frame/jpanel上(使用.jar,所以我不知道它是否在jfame或jpanel上)。第一张图像是唯一正确显示的图像。我尝试过重新绘制和重新验证,但它不起作用。任何帮助将不胜感激。
这是 for 循环。
//loop through all test images and display
for(int i = 0; i < images.length; i++)
{
int xAxis = 1;
int yAxis = 1;
imageHandler.displayAnImage(images[i], jvis, xAxis, yAxis, "");
//if third image in the row then take a new line
if(i % 3 == 0)
{
yAxis = yAxis + 300;
}
//display each image side by side
xAxis = xAxis + 300;
}
谢谢
最佳答案
您需要在开始循环之前初始化 xAxis 和 yAxis 变量,在每个循环开始时,将它们初始化回 1,以便所有图像都绘制在同一位置。
//loop through all test images and display
int xAxis = 1;
int yAxis = 1;
for(int i = 0; i < images.length; i++)
{
imageHandler.displayAnImage(images[i], jvis, xAxis, yAxis, "");
//if third image in the row then take a new line
if(i % 3 == 0)
{
yAxis = yAxis + 300;
}
//display each image side by side
xAxis = xAxis + 300;
}
关于java - 在 Java 中的 for 循环中显示 BufferedImages 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29063624/