带有alpha的JavaFX8画布快照

带有alpha的JavaFX8画布快照,java,canvas,javafx,Java,Canvas,Javafx,我目前正在开发一个绘画程序(类似于Gimp和Photoshop),为了做到这一点,我需要图层。我创建了一个名为JImage的类,它有一个arraylistlayers和一些方法 public Image toImage(){ //Returns the final image which is all its layers combined into one canvas and snapshotted. Canvas c = new Canvas(width, height); //w

我目前正在开发一个绘画程序(类似于Gimp和Photoshop),为了做到这一点,我需要图层。我创建了一个名为JImage的类,它有一个
arraylistlayers
和一些方法

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层,并且背景始终为白色。这会阻止我在没有丑陋的白色背景的情况下将其发送到文件。有没有一种方法我可以得到一个图像从多个画布与阿尔法层?我更愿意使用JavaFX来解决这个问题,所以在拍摄快照之前,请给出JavaFX范围内的解决方案

SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
Image snapshot = currLayer.snapshot(params, null);
从javadoc:

将填充设置为指定值。这用于在渲染节点之前填充正在渲染的整个图像。null值表示填充应使用白色。默认值为空

在拍摄快照之前,将快照参数设置为

SnapshotParameters params = new SnapshotParameters();
params.setFill(Color.TRANSPARENT);
Image snapshot = currLayer.snapshot(params, null);
从javadoc:

将填充设置为指定值。这用于在渲染节点之前填充正在渲染的整个图像。null值表示填充应使用白色。默认值为空


非常感谢。你发现了我找不到的问题!我是JavaFX的新手,谢谢你的帮助!非常感谢。你发现了我找不到的问题!我是JavaFX的新手,谢谢你的帮助!