我目前正在开发一个绘画程序(类似于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));
}
我的问题是,当使用
canvas.snapshot(SnapshotParameters,WritableImage)
时,alpha层不被包含在内,背景总是白色的。这会导致我无法将其发送到文件中,因为它会有一个丑陋的白色背景。有没有办法从多个带有alpha层的画布中获取图像?我希望使用JavaFX解决此问题,请给出JavaFX范围内的解决方案。