【发布时间】:2017-04-11 03:02:42
【问题描述】:
我正在创建供用户选择的原始图像。我希望图像在用户点击后改变颜色
FileInputStream seats_fileInputStream = new FileInputStream("seat.png");
Image seats_image = new Image(seats_fileInputStream,50,50,false,false);
ImageView[] seats = new ImageView[30];
for(int i = 0;i<30;i++){
seats[i] = new ImageView(seats_image);
}
HBox seatsRaw_hbox[] = new HBox[5];
VBox seatsLine_vbox = new VBox();
int seatsCount = 0;
for(int i=0;i<5;i++){
seatsRaw_hbox[i]= new HBox();
for(int j=0;j<6;j++){
seatsRaw_hbox[i].getChildren().addAll(seats[seatsCount]);
seatsCount++;
}
seatsLine_vbox.getChildren().add(seatsRaw_hbox[i]);
}
BorderPane Test = new BorderPane();
Test.setCenter(seatsLine_vbox);
我试图在点击后将图像更改为绿色:
Color targetColor = Color.GREEN;
ColorAdjust colorAdjust = new ColorAdjust();
colorAdjust.setSaturation(targetColor.getSaturation());
colorAdjust.setHue(targetColor.getHue());
colorAdjust.setBrightness(targetColor.getBrightness());
seats[0].setOnMouseClicked(e->{
seats[0].setEffect(colorAdjust);
});
但我总是得到奇怪的颜色
原图:
点击后得到的奇怪结果:
【问题讨论】:
-
“我总是有奇怪的颜色” -- 请解释一下并提供一些示例。
-
还有
seat.png图像的外观如何? -
@JimGarrison 我已经编辑了问题
-
@fabian 我已经编辑了问题
-
输出应该是绿色矩形或圆角绿色矩形或深灰色区域变为绿色的矩形或...?