Android Question EncodeBase64/DecodeBase64 with StringUtils

zsezo

Member
Licensed User
Longtime User
Hello!

I have a problem too with read/write file and or EncodeBase64/DecodeBase64
Can I ask somebody to explain what I missed?

I tried to encode the file on my side, and immediately decode back just for test. But the two files are significantly different!

What did I do wrong?

B4X:
Dim su As StringUtils
Dim out1 As OutputStream
Dim in1 As InputStream
Dim str1 As String
   
out1.InitializeToBytesArray(100) 'size not really important
File.Copy2(File.OpenInput(File.DirRootExternal, "sign18112401.png"), out1)
str1=su.EncodeBase64(out1.ToBytesArray)
   
in1.InitializeFromBytesArray(su.DecodeBase64(str1),0,str1.Length)
File.Copy2(in1,File.OpenOutput(File.DirRootExternal, "sign18112401_b.png",False))

The new file ("sign18112401_b.png") is totally garbaged!


Thanks in advance!
 

Attachments

  • sign18112401.png
    sign18112401.png
    42.1 KB · Views: 337
Top