Hi
I try to load blob images into b4xtable cells
I use that code but it is not working...
I can't understand what I do wrong.
I work with blob and general with images for first time.
When I try to display one image in a view as @Erel example I can do it but not here.
I think it is more complicate for me.
Can anyone help?
The error I get is
Thank you
I try to load blob images into b4xtable cells
I use that code but it is not working...
I can't understand what I do wrong.
I work with blob and general with images for first time.
When I try to display one image in a view as @Erel example I can do it but not here.
I think it is more complicate for me.
Can anyone help?
B4X:
Sub ItemListWithPhotos
B4XPicTable.AllowSmallRowHeightModifications = False
B4XPicTable.RowHeight = 80dip
B4XPicTable.SearchField.TextField.Enabled = False
For i = 0 To NumberOfColumns - 1
B4XPicTable.AddColumn(i, B4XPicTable.COLUMN_TYPE_TEXT)
Next
'Force the creation of the cells.
B4XPicTable.MaximumRowsPerPage = 20
B4XPicTable.BuildLayoutsCache(B4XPicTable.MaximumRowsPerPage)
For Each col As B4XTableColumn In B4XPicTable.Columns
col.Sortable = False
col.Width = 100%x / NumberOfColumns
For i = 0 To col.CellsLayouts.Size - 1
Dim pnl As B4XView = col.CellsLayouts.Get(i)
pnl.GetView(0).Visible = False 'hide the label
If i > 0 Then 'i = 0 is the header
Dim iv As ImageView
iv.Initialize("")
pnl.AddView(iv, 2dip, 2dip, col.Width - 4dip, B4XPicTable.RowHeight - 4dip)
End If
Next
Next
LoadData
B4XPicTable.mBase.Visible = True
End Sub
Sub LoadData
Dim Data As List
Data.Initialize
Dim row(NumberOfColumns) As Object
Dim index As Int = -1
Dim SqlScript As String
Dim Curs1 As Cursor
Dim Buffer() As Byte 'declare an empty byte array
SqlScript = $"SELECT LOCAL_ESFIItemBlob.BlobData, LOCAL_ESFIItemBlob.BlobSize, IFNULL(LOCAL_ESFIItem.Code, '') AS Code
FROM LOCAL_ESFIItemBlob
LEFT JOIN LOCAL_ESFIItem ON LOCAL_ESFIItem.Code = LOCAL_ESFIItemBlob.ESFIItem_Code
ORDER BY LOCAL_ESFIItem.Description "$
Starter.LocalSQL.Initialize(Starter.SafeFolder, "DVDatabase.db", True)
Curs1 = Starter.LocalSQL.ExecQuery(SqlScript)
' For i = 0 To Curs1.RowCount - 1
For i = 0 To 10
Curs1.Position = i
Main.G1.Item_Comment1 = Curs1.GetString("Code")
Buffer = Curs1.GetBlob("BlobData")
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Main.G1.Bitmap1.Initialize2(InputStream1)
index = (index + 1) Mod NumberOfColumns
row(index) = InputStream1.ReadBytes(Buffer, 0, Buffer.length)
If index = NumberOfColumns - 1 Then
Data.Add(row)
Dim row(NumberOfColumns) As Object
End If
Next
If index < NumberOfColumns - 1 Then
'last incomplete row
For i = index + 1 To NumberOfColumns - 1
row(index) = InputStream1
Next
Data.Add(row)
End If
InputStream1.Close
B4XPicTable.SetData(Data)
End Sub
Sub B4XPicTable_DataUpdated
Dim InputStream1 As InputStream
Dim row As Map
For i = 0 To B4XPicTable.VisibleRowIds.Size - 1
Dim RowId As Long = B4XPicTable.VisibleRowIds.Get(i)
If RowId > 0 Then
row = B4XPicTable.GetRow(RowId)
Else
row = CreateMap()
End If
For Each column As B4XTableColumn In B4XPicTable.Columns
Dim pnl As B4XView = column.CellsLayouts.Get(i + 1) '+1 because the first cell is the header
Dim iv As B4XView = pnl.GetView(1) 'ImageView will be the 2nd child of the panel. The built-in label is the first.
If row.GetDefault(column.Id, "") <> "" Then
Dim Bitmap1 As Bitmap
InputStream1 = row.Get(column.Id)
Bitmap1.Initialize2(InputStream1)
InputStream1.Close
Else
iv.SetBitmap(Null)
End If
Next
Next
btnNext.Enabled = B4XPicTable.lblNext.Tag
btnPrev.Enabled = B4XPicTable.lblBack.Tag
End Sub
The error I get is
Error occurred on line: 85 (ESFIItems)
java.lang.IllegalArgumentException: method anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2 argument 1 has type java.io.InputStream, got java.lang.String
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1083)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1030)
at gr.iosif.droidview.b4xtable$ResumableSub_ImplUpdateDataFromQuery.resume(b4xtable.java:2970)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1705)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5376)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Thank you
Last edited: