Android Question ImageToBytes Error?

RishiKumar2210

Active Member
I want to convert Images to Bytes. I Attached Error Image

B4X:
Public Sub ImageToBytes(Image As Bitmap) As Byte()
    If is_imageextension = "png" Then
        Dim ls_imageformat As String = "PNG"
    Else IF is_imageextension = "jpg" Or is_imageextension = "jpeg" Then
        Dim ls_imageformat As String = "JPEG"
    End If
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    Image.WriteToStream(out, 100, ls_imageformat)
    out.Close
    Return out.ToBytesArray
End Sub

B4X:
Dim ls_photostring As String = ""
        Dim ls_byte() As Byte
        ibit_bitmap = image_imageview.Bitmap
        ls_byte = ImageToBytes(ibit_bitmap)
        Log(2)
        Dim ls_stringutils As StringUtils
        ls_photostring = ls_stringutils.EncodeBase64(ls_byte)

The Following is the error message

java.lang.IllegalArgumentException: No enum constant android.graphics.Bitmap.CompressFormat.
 

teddybear

Well-Known Member
Licensed User
Check the image file name, I suspect the is_imageextension is uppercase JPG or PNG.
Try this

B4X:
is_imageextension.ToLowerCase="png"
 
Upvote 0
Top