【发布时间】:2015-03-29 04:19:59
【问题描述】:
我正在尝试创建一种方法,该方法将获取图像中的所有红色值并仅显示红色值。我的 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 对象的红色二维数组设置为这个 simpleRGB 对象的红色二维数组,然后使用嵌套的 for 循环来将绿色和蓝色二维数组值都设置为零。我只是不确定如何做到这一点。
public SimpleRGB getRedImage()
{
// This is where I am confused.
}
}
【问题讨论】:
-
所以 getRedImage 循环遍历图像中的所有像素,只返回每个像素的红色值,然后用这些红色值构建/填充二维数组?听起来您需要研究一些用于图像处理的标准 Java 类。