我试图重新缩放图像数组,使它们都具有相同的宽度和高度。我无法返回数组。任何帮助都会很棒。缩放图像阵列Java
public static Picture[] resize(Picture[] slides, String[] args) {
int w = 298;
int h = 298;
Picture [] source = new Picture [Integer.parseInt(args[0])];
for (int ti = 0; ti < w; ti++){
for (int tj = 0; tj < h; tj++){
Picture [] target = new Picture[ti+1];
int si = tj * source[ti].width()/w;
int sj = tj * source[tj].height()/h;
target[ti].set(ti, tj, source[0].get(si, sj));
}
}
return target;
}
我不知道这段代码应该如何工作。你为什么要创建一个图片数组,其中包含的元素数量与您在源图片中水平扫描的像素数量一样多?为什么你永远不会创建目标'Picture'对象,并设置一个'target [ti]'显然是'null'的像素?为什么你只能访问'source'的第0个元素?我认为你需要回到如何使用数组的基本原则:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html – millimoose 2013-02-17 20:42:48
(无论如何,投票关闭,因为代码上面的例子几乎是无法修复的,并且在这个问题中存在主要的XY问题。) – millimoose 2013-02-17 20:44:16