### Screenshot using JavaObjects

This Sub shows how to make a screenshot using JavaObjects.
' Make the screenshot and create the PNG file
' Parameter:
' For the Screen set doscreen = True else App Window is captured
' Filename to store the image
`Sub screenShot(doscreen As Boolean, filename As String)
Log("screenshot :: Start")
Log("Get Screensize...")
Dim joSZ As JavaObject
joSZ.InitializeStatic("java.awt.Toolkit")
' To get the screensize use
' joSZ.RunMethodJO("getDefaultToolkit", Null).RunMethod("getScreenSize", Null))
Log("Create Rectangle...")
Dim joR As JavaObject
If doscreen = True Then
Log("For the Screen...")
'For fullscreen use:
joR.InitializeNewInstance("java.awt.Rectangle", Array(joSZ.RunMethodJO("getDefaultToolkit", Null).RunMethod("getScreenSize", Null)))
Else
Log("For the AppWindow...")
' Get the form size
Dim wl As Int = MainForm.WindowLeft
Dim wt As Int = MainForm.WindowTop
Dim wh As Int = MainForm.WindowHeight
Dim ww As Int = MainForm.WindowWidth
Log("Dimensions: x,y,h,w: "& MainForm.WindowLeft & "," & MainForm.WindowTop & "," & MainForm.WindowHeight & "," & MainForm.WindowWidth)
' For the app window use:
'int x, int y, int width, int height
joR.InitializeNewInstance("java.awt.Rectangle", Array As Object(wl, wt, ww, wh))
End If
Log("Init the Robot...")
Dim joRobot As JavaObject
joRobot.InitializeNewInstance("java.awt.Robot", Null)
' To capture the screen use
' joRobot.RunMethod("createScreenCapture", Array(joR))
Log("Create the File...")
Dim joF As JavaObject
' Create the file instances for the files (the constructor)
joF.InitializeNewInstance("java.io.File", Array As Object(filename))
Log("Capture & Save the Image...")
Dim joWI As JavaObject
joWI.InitializeStatic("javax.imageio.ImageIO")
joWI.RunMethod("write", Array As Object(joRobot.RunMethod("createScreenCapture", Array(joR)), "PNG", joF))
Log("screenshot :: End")
End Sub`
Examples
Private CFILE As String = "screenshot.png"
`Sub btnScreenshot_Action
screenShot(True, CFILE)
End Sub`
`Sub btnAppshot_Action
screenShot(False, CFILE)
End Sub`

Changed: , Category: Image and ImageView, File: T6C199M1467.htm, ID: 1467