'Adds image span: bitmap,width,height,True or False
Public Sub Image(bmp As Bitmap, Width As Int, Height As Int, Baseline As Boolean) As PCSBuilder 'Mahares
cs.Image(bmp, Width, Height, Baseline)
'Some additional code must be missing here to add the image to the list
'Need to convert Bitmap to a byte array since Bitmaps are not serializable
'Use an array to hold more than two parameters and a "stub" method (Image2) that can deal
' with the parameter array
data.Add(Array("Image2",Array(ImageToBytes(bmp), Width, Height, Baseline)))
Return Me
End Sub
'Serves two purposes
'1) Circumvent limitations of CallSub parameters
'2) Convert byte array to Bitmap
Private Sub Image2(args() As Object) As PCSBuilder
Return Image(BytesToImage(args(0)), args(1), args(2), args(3))
End Sub
'https://www.b4x.com/android/forum/threads/b4x-bytes-to-file.70111/#post-445167
'Slight adaptation to make it work in this context (renamed Image variable to bmp)
Public Sub ImageToBytes(bmp As Bitmap) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(0)
bmp.WriteToStream(out, 100, "JPEG")
out.Close
Return out.ToBytesArray
End Sub
Public Sub BytesToImage(bytes() As Byte) As Bitmap
Dim In As InputStream
In.InitializeFromBytesArray(bytes, 0, bytes.Length)
Dim bmp As Bitmap
bmp.Initialize2(In)
Return bmp
End Sub