Hi,
Here is my test code:
The problem is that after refreshing B4XTable1
Gravity.FILL does not function properly as intended.
Only after restarting the Gravity.FILL application does the pictures work as it should.
What could be the reason?
To determine the size of the image, I use:
Buffer = rm.ImageToBytes(rm.ResizeBitmapMaxByte(bmp ,MaxByte))
Does it matter ??
Here is my test code:
The problem is that after refreshing B4XTable1
Gravity.FILL does not function properly as intended.
Only after restarting the Gravity.FILL application does the pictures work as it should.
What could be the reason?
To determine the size of the image, I use:
Buffer = rm.ImageToBytes(rm.ResizeBitmapMaxByte(bmp ,MaxByte))
Does it matter ??
B4X:
Public Sub [B]ResizeBitmapMaxByte[/B](Original As Bitmap, MaxByte As Long) As Bitmap
Dim ByteSize As Long
Dim ObjectBitmap As JavaObject = Original
Dim API_Level As JavaObject
API_Level.InitializeStatic("android.os.Build.VERSION")
If API_Level.GetField("SDK_INT") >= 19 Then 'kitkat
ByteSize = ObjectBitmap.RunMethod("getAllocationByteCount", Null)
else if API_Level.GetField("SDK_INT") >= 12 Then 'Android 3.1
ByteSize = ObjectBitmap.RunMethod("getByteCount", Null)
Else 'Android versions
ByteSize = ObjectBitmap.RunMethod("getRowBytes", Null) * Original.Height
End If
Dim Ratio As Float = Sqrt(MaxByte/ByteSize)
If Ratio < 1 Then
Width = (Original.Width * Ratio)
Height = (Original.Height * Ratio)
Return Original.Resize(Width, Height, True)
Else
Return Original
End If
End Sub
B4X:
Private Sub B4XTable1_DataUpdated
Try
Dim sf As Object = SQL1.ExecQueryAsync("SQL","SELECT Blob FROM customers", Null)
Wait for (sf) SQL_QueryComplete(Success As Boolean, rs As ResultSet)
If Success Then
For i = 0 To B4XTable1.VisibleRowIds.Size - 1 'row(s)
Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
If RowId > 0 Then 'View the content of the fields
...
Dim p As B4XView = BlobColumn.CellsLayouts.Get(i + 1) '+1 because the first cell is the header
Dim v As ImageView
v.Initialize("")
v.Gravity = Gravity.FILL ------------------------------- ???
p.AddView(v, 1dip, 1dip, BlobColumn.Width - 2dip, B4XTable1.RowHeight - 1dip)
rs.Position = RowId -1 'The first valid position is 0.
Dim p As B4XView = BlobColumn.CellsLayouts.Get(i + 1) '+1 because the first cell is the header
Dim b As B4XView = p.GetView(1)
Dim Buffer() As Byte = rs.GetBlob("Blob")
If Buffer <> Null Then
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
Dim bmp As Bitmap
bmp.Initialize2(InputStream1)
InputStream1.Close
b.SetBitmap(bmp)
v.Gravity = Gravity.FILL ------------------------------------ ???
Else
b.SetBitmap(Null)
End If
Else
Exit 'The End View the content of the fields
End If
Next
End If
rs.Close
...
Catch
Log(LastException.Message)
End Try
End Sub