【发布时间】:2015-11-05 04:56:17
【问题描述】:
我目前正在开发一个绘图程序(类似于 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 范围内给出解决方案。
【问题讨论】: