I am getting the error below on Read sub.
How to acomplish this?
Log:
Whole code:
How to acomplish this?
Log:
CreateTable: CREATE TABLE IF NOT EXISTS [tids] ([id] BLOB PRIMARY KEY, [name] TEXT)
Records: 4
(IllegalArgumentException) java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
Whole code:
B4X:
#Region Project Attributes
#MainFormWidth: 200
#MainFormHeight: 200
#AdditionalJar: sqlite-jdbc-3.7.2
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private SQL1 As SQL
Private c3po As AWTRobot
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
SQL1.InitializeSQLite(File.DirApp, "Dados.db", True)
CreateDatabase
Store
Read
End Sub
Sub Read
Dim Cursor1 As ResultSet
Cursor1 = SQL1.ExecQuery("SELECT id FROM tids LIMIT 1")
Dim Buffer() As Byte 'declare an empty byte array
Buffer = Cursor1.GetBlob("id")
Dim Bitmap1 As B4XBitmap = BytesToImage(Buffer)
StoreJPEG(Bitmap1, DateTime.Now)
End Sub
Sub StoreJPEG(bitmap As B4XBitmap, Name As String)
Try
Dim out As OutputStream
out = File.OpenOutput(File.DirApp, Name & ".JPEG", False)
bitmap.WriteToStream(out, 100, "JPEG")
out.Close
Catch
Log(LastException)
End Try
End Sub
Sub Store
Dim bmp1 As B4XBitmap = Capture(Rnd(1,200),Rnd(1,200),Rnd(1,200),Rnd(1,200))
Dim BC As BitmapCreator
BC.Initialize(bmp1.Width,bmp1.Height)
BC.CopyPixelsFromBitmap(bmp1)
SQL1.ExecNonQuery2($"INSERT INTO tids (id, name) VALUES (?, '${DateTime.Now}')"$, Array As Object(BC.Buffer))
' just for show that the record was stored correctly
Dim Records As Int
Records = SQL1.ExecQuerySingleResult("SELECT count(*) FROM tids")
Log("Records: " & Records)
End Sub
Sub CreateDatabase
Dim m As Map
m.Initialize
m.Put("id", DBUtils.DB_BLOB)
m.Put("name", DBUtils.DB_TEXT)
DBUtils.CreateTable(SQL1, "tids", m, "id")
End Sub
Sub Capture(x As Int, y As Int, w As Int, h As Int) As B4XBitmap
c3po.ScreenCurrentRectangleSetAsArbitrary(x, y, w, h)
Return BytesToImage(c3po.ScreenCaptureAsByteArray)
End Sub
Public Sub BytesToImage(bytes() As Byte) As B4XBitmap
Dim In As InputStream
In.InitializeFromBytesArray(bytes, 0, bytes.Length)
Dim bmp As Image
bmp.Initialize2(In)
Return bmp
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