Private Sub BitmapToString(bmp As B4XBitmap) As String 'XUI
Dim out As OutputStream
out.InitializeToBytesArray(1000)
bmp.WriteToStream(out, 100, "PNG")
out.Close
Dim su As StringUtils
Return su.EncodeBase64(out.ToBytesArray)
End Sub
2- ImageToBytes(Image As Bitmap)
ImageToBytes(Image As Bitmap):
Public Sub ImageToBytes(Image As Bitmap) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(0)
Image.WriteToStream(out, 100, "JPEG")
out.Close
Return out.ToBytesArray
End Sub
3- File.ReadBytes(dir As String, fileName As String)
BitmapToString:
1. Uses PNG. Unlike your original JPEG image.
2. It encodes with base64 which adds about 33% overhead (with the advantage of encoding the raw bytes as a valid string).
ImageToBytes does use JPEG. You can play with the quality. It will change the file size.
Thank you for your explanation.
About BitmapToString i got it but what is difference between ImageToBytes(Image As Bitmap) with File.ReadBytes(dir As String, fileName As String) ?
size returned with ImageToBytes over than size returned with File.ReadBytes