Android Question Save/Load text formatted

ilan

Expert
Licensed User
Longtime User
hi

is it possible to load/save formatted text? like text with specific color, text size, bold, underlined,...
so save it and load it from a text file?

thanx
 

ilan

Expert
Licensed User
Longtime User

You need to convert the image to bytes and save it like that using kvs and then reload again. I will try to do it when i get back to my pc.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I think it is missing adding the bitmap to the list.
Something like this? (untested)
B4X:
'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
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…