|
33 | 33 | import java.util.Map; |
34 | 34 |
|
35 | 35 | import javafx.scene.SnapshotParameters; |
| 36 | +import javafx.scene.canvas.Canvas; |
36 | 37 | import javafx.scene.canvas.GraphicsContext; |
37 | 38 | import javafx.scene.effect.BlendMode; |
38 | 39 | import javafx.scene.image.PixelFormat; |
@@ -112,7 +113,12 @@ public PGraphicsFX2D() { } |
112 | 113 | //public void setPath(String path) |
113 | 114 |
|
114 | 115 |
|
115 | | - //public void setSize(int width, int height) |
| 116 | + public void setSize(int width, int height) { |
| 117 | + if (!primaryGraphics && context == null) { |
| 118 | + context = new Canvas(width, height).getGraphicsContext2D(); |
| 119 | + } |
| 120 | + super.setSize(width, height); |
| 121 | + } |
116 | 122 |
|
117 | 123 |
|
118 | 124 | //public void dispose() |
@@ -157,6 +163,8 @@ public void endDraw() { |
157 | 163 | if (!primaryGraphics) { |
158 | 164 | // TODO this is probably overkill for most tasks... |
159 | 165 | loadPixels(); |
| 166 | + // Make the image cache reload this. |
| 167 | + modified = true; |
160 | 168 | } |
161 | 169 | } |
162 | 170 |
|
@@ -2156,12 +2164,15 @@ public void loadPixels() { |
2156 | 2164 | snapshotImage = new WritableImage(pixelWidth, pixelHeight); |
2157 | 2165 | } |
2158 | 2166 |
|
2159 | | - SnapshotParameters sp = null; |
| 2167 | + SnapshotParameters sp = new SnapshotParameters(); |
| 2168 | + if (!primaryGraphics) { |
| 2169 | + // Alpha channel should not be made white (but only if offscreen) |
| 2170 | + sp.setFill(Color.TRANSPARENT); |
| 2171 | + } |
2160 | 2172 | if (pixelDensity != 1) { |
2161 | | - sp = new SnapshotParameters(); |
2162 | 2173 | sp.setTransform(Transform.scale(pixelDensity, pixelDensity)); |
2163 | 2174 | } |
2164 | | - snapshotImage = ((PSurfaceFX) surface).canvas.snapshot(sp, snapshotImage); |
| 2175 | + snapshotImage = context.getCanvas().snapshot(sp, snapshotImage); |
2165 | 2176 | PixelReader pr = snapshotImage.getPixelReader(); |
2166 | 2177 | pr.getPixels(0, 0, pixelWidth, pixelHeight, argbFormat, pixels, 0, pixelWidth); |
2167 | 2178 |
|
|
0 commit comments