私はBufferedImage
をjavaでフィルタリングしたいですか?フィルタリングrgbイメージは、Javaで一度だけ動作します
private void changeRGB(BufferedImage image, int colour) {
int width = image.getWidth();
int height = image.getHeight();
int newColor = 0;
for(int y = 0; y < height; y++){
for(int x = 0; x < width; x++){
Color color = new Color(image.getRGB(x,y));
int red = color.getRed();
int green = color.getGreen();
int blue = color.getBlue();
if (colour == 1) {
newColor = new Color(red, 0, 0).getRGB();
} else if (colour == 2) {
newColor = new Color(0, green, 0).getRGB();
} else if (colour == 3) {
newColor = new Color(0, 0, blue).getRGB();
}
image.setRGB(x, y, newColor);
}
}
icon = new ImageIcon(image);
this.lblFilteredImage.setIcon(icon);
}
と私が押した場合、例えば:
現在、私はこのコードの部分を持っています
choice = 2; changeRGB(img, choice);
このコードは、時間を動作し、私はこれらのボタンのいずれかを押すと、2回目は、それが
'color'と' colour'変数は同じスコープにありますか?これらの変数名の1つを間違いなく変更する必要があります...同じ画像に複数回適用すると、色を抽出するので、既に抽出した同じチャンネルを抽出するか、画像が黒くなるため、画像も変化しません以前は0に設定されていました... – fabian
しかし、イメージが黒くならないように、どうすれば問題を解決できますか? – mafioso
2つの画像を使用します。一方はソースを、もう一方はフィルタリングしたデータを使用します。異なるフィルタを適用することは、これらのフィルタでは意味がありません。だから私は一度にこれらのフィルタの1つだけを適用したいと思います。 – fabian