Sub SaveScreenShot
Dim strDefault As String
If iCurrentPanelType = ePanelType.SQLEdit Then
If lblOpenedSQL.Text.Length > 0 Then
strDefault = lblOpenedSQL.Text
End If
End If
Dim rs As ResumableSub = Dialog.Show(Activity, Array As Object("OK", "Cancel"), _
"Save screenshot", strDefault, _
"Type in the File name." & CRLF & CRLF & "Don't put in the file extension (will be .png)", _
0, False, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, Null, False)
Wait For (rs) Complete (strFile As String)
If strFile = "Cancel" Then Return
Dim bmp As Bitmap
bmp = TakeScreenshot
SaveBitmap(bmp, strFile & ".png")
End Sub
Sub SaveBitmap(bmp As Bitmap, strFile As String)
Dim Out As OutputStream
Out = File.OpenOutput(Starter.strAppDir, strFile, False)
bmp.WriteToStream(Out, 100, "PNG")
Out.Close
End Sub
Sub TakeScreenshot As Bitmap
Dim jo As JavaObject
jo.InitializeContext
Dim decor As JavaObject = jo.RunMethodJO("getWindow", Null).RunMethod("getDecorView", Null)
Dim decorChild As JavaObject = decor.RunMethod("getChildAt", Array(0))
decorChild.RunMethod("setDrawingCacheEnabled", Array(True))
decorChild.RunMethod("buildDrawingCache", Null)
Dim bmp As Bitmap = decorChild.RunMethod("getDrawingCache", Array(True))
bmp.Initialize3(bmp)
decorChild.RunMethod("setDrawingCacheEnabled", Array(False))
Return bmp
End Sub