### Snapshot MainForm

Example creating a snapshot of the mainform when the appication runs in fullscreen on a Raspberry Pi.
Tested on a RPi 3 Model B+ running Stretch, jdk1.8.0_162, Gluon JavaFXPorts armv6hf-sdk-8.60.9.
Requirements
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
'The jar jfxrt is required for the class SwingFXUtils to make a screenshot of the mainform when running on the RPi.
'To avoid runtime error: java.lang.NoClassDefFoundError: javafx/embed/swing/SwingFXUtils
'Copied c:\Program Files (x86)\Java\jdk8\jre\lib\ext\jfxrt.jar to the B4J additional libraries folder.
'Note: Check your JDK path prior copying to the B4J additional library folder.
#AdditionalJar: jfxrt
#MergeLibraries: True
#End Region
Example sub make a snapshot of the mainform
`Sub FormSnapShot 'ignore
Dim img As Image = MainForm.RootPane.Snapshot
Dim Out As OutputStream = File.OpenOutput(File.DirApp, "rpicputemperaturedashboard.png", False)
img.WriteToStream(Out)
Out.Close
End Sub`
Note B4J-Bridge
When running via the B4J-Bridge, the screenshot is stored in the tempjars folder.
Inline Java Solution
As of interest as solution using Inline Java
`Sub Process_Globals
Private joInlineJava As JavaObject = Me
...
if JAVA
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.WritableImage;
import java.io.File;
import java.awt.image.RenderedImage;
import javax.imageio.ImageIO;
public static void SaveWritableImage(WritableImage Image, String FileName) throws Exception {
File File = new File(FileName);
RenderedImage renderedImage = SwingFXUtils.fromFXImage(Image, null);
ImageIO.write(renderedImage, "png", File);
}
End If
`Sub FormSnapShot
Dim joScene As JavaObject = MainForm.RootPane
joScene = joScene.RunMethod("getScene",Null)
Dim joWritebleImage As JavaObject
joWritebleImage.InitializeNewInstance("javafx.scene.image.WritableImage", Array(600, 600))
joScene.RunMethod("snapshot", Array(joWritebleImage))
joInlineJava.RunMethod("SaveWritableImage", Array(joWritebleImage, "rpicputemperaturedashboard.png"))
End Sub`
`

Changed: 2018-03-28 14:22, Category: Raspberry Pi UI JavaFXPorts, File: T6C239M2151.htm, ID: 2151