0
好吧,所以我卡在一个方法,我必须返回图像中的每个组件,但每个组件的颜色随机化。这是我到目前为止:随机化图像组件的颜色
public Picture colourComponentImage()
{
Picture picture = new Picture(fileLocation);
int width = picture.width();
int height = picture.height();
// convert to black and white
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Color color = picture.get(x, y);
if (Luminance.lum(color) < threshold)
{
picture.set(x, y, Color.BLACK);
}
else
{
picture.set(x, y, Color.WHITE);
}
}
}
// union - find data structure
connected(height, width);
find(height);
union(height, width);
// Randomises the colour of each component
Random random = new Random();
float r = random.nextFloat();
float g = random.nextFloat();
float b = random.nextFloat();
Color randomColor = new Color(r, g, b);
return picture;
}
有人可以告诉我我要去哪里吗?
什么不会在你目前的工作方式? – Junuxx 2014-10-09 09:02:26
当我运行该程序时,图片不会显示,因为我无法看到图片,我不知道颜色随机化是否正常工作 – 2014-10-09 09:10:54
你知道如何在java中绘图吗?你需要一个顶级的容器(框架),并在其图形上绘制...你知道这一点,你是否在你的代码中这样做?如果**是**请提交该代码... if ** no ** plaes study http://docs.oracle.com/javase/tutorial/2d/images/ – 2014-10-09 09:45:18