#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private ImageView1 As ImageView
Private Image1 As Image
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
Dim ScreenCap As JavaObject
ScreenCap.InitializeNewInstance("java.awt.Robot",Null)
Dim Rectangle As Object = NewRectangle(100,100,300,300)
Dim Bimg As Object = ScreenCap.RunMethod("createScreenCapture",Array(Rectangle))
Dim Bytes() As Byte = Bimg2Bytes(Bimg)
'Convert the bytes array to an image
Dim IStream As InputStream
IStream.InitializeFromBytesArray(Bytes,0,Bytes.Length)
Image1.Initialize2(IStream)
'Set the image to an ImageView
ImageView1.SetImage(Image1)
End Sub
Private Sub NewRectangle(X As Int, Y As Int, Width As Int, Height As Int) As Object
Dim R As JavaObject
R.InitializeNewInstance("java.awt.Rectangle",Array(X,Y,Width,Height))
Return R
End Sub
Private Sub Bimg2Bytes(Bimg As Object) As Byte()
Dim BAOS As JavaObject
BAOS.InitializeNewInstance("java.io.ByteArrayOutputStream",Null)
Dim ImageIO As JavaObject
ImageIO.InitializeStatic("javax.imageio.ImageIO")
ImageIO.RunMethod("write",Array(Bimg,"png",BAOS))
Return BAOS.RunMethod("toByteArray",Null)
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub