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