我正在尝试创建一种方法,该方法将获取图像中的所有红色值并仅显示红色值。我的 getRedImage() 方法遇到问题。我对此很陌生,任何帮助将不胜感激!
public class SimpleRGB
{
private int width, height;
private int[][] red = new int[1000][1000];
这部分获取红色值并将其设置到我的二维红色数组的指定位置:
public void setRed(int x, int y, int aRed)
{
red[x][y] = aRed;
}
这部分获取坐标 (x,y) 处的红色值并返回它:
public int getRed(int x, int y)
{
int thisr = red[x][y];
return thisr;
}
我不确定如何表达这部分。我知道我需要创建一个新的 SimpleRGB 对象来返回,然后使用嵌套的 for 循环将新的简单 RGB 对象的红色 2D 数组设置为此 simpleRGB 对象的红色 2D 数组,然后使用嵌套的 for 循环将绿色和蓝色二维数组值设置为全零。我只是不确定如何做到这一点。
public SimpleRGB getRedImage()
{
// This is where I am confused.
}
}
在二维数组中循环很容易
但我认为这不是正确的方法。
private int[][] red = new int[1000][1000];
for (int i = 0; i < 1000; i++) {
for(int j = 0; j < 1000; j++) {
System.out.println(red[i][j]);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)