我目前正在开发一个绘画程序(类似于Gimp和Photoshop),为了做到这一点,我将需要图层。我创建了一个名为JImage的类,该类具有ArrayList<Canvas> layers和一些方法。
public Image toImage(){ //Returns the final image which is all its layers combined into one canvas and snapshotted.
Canvas c = new Canvas(width, height); //width and height are determined in the constructor
for(int i=layers.size()-1;i>=0;i--){
Canvas currLayer = layers.get(i);
c.getGraphicsContext2D().drawImage(currLayer.snapshot(new SnapshotParameters(), new WritableImage(width,height)));
}
return c.snapshot(new SnapshotParameters(), new WritableImage(width,height));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当您这样做时canvas.snapshot(SnapshotParameters,WritableImage),不包括Alpha层,并且背景始终为白色。这样可以防止我将其发送到没有丑陋白色背景的文件中。有什么办法可以从具有alpha层的多个画布中获取图像?我希望将JavaFX用于此解决方案,因此请在JavaFX的范围内提供解决方案。
我正在使用 CSS 在 JavaFX 中制作自定义主题,并且我正在尝试使所有 HBox 和 VBox 具有中心对齐。我到处找找父母或HBoxes是否有造型课,但我似乎找不到。我知道我可以这样做,HBox.setAligent(Pos.CENTER);但我不想为我拥有的每个 HBox 或 VBox 键入该命令。我该怎么做才能使所有 HBox 都具有中心对齐,而不必使用自定义类并将其放入 CSS 文件中?