2
我目前正在绘制程序(类似于GIMP和Photoshop),为了做到这一点,我将需要图层。我创建了一个名为JImage的类,它有一个ArrayList<Canvas> layers
和一些方法。JavaFX 8 Canvas快照与阿尔法
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的范围内给出解决方案。
谢谢!你发现了我找不到的问题!我是JavaFX的新手,非常感谢您的帮助! – Jaboyc