Question

This is the method I use on .NET to create the string that sent to the android App, the image is System.Drawing.Image type convert in Bitmap:

Public Shared Function SerializeObject(ByVal objeto As Bitmap) As String        

    Dim bitmapBytes As Byte()
    Dim stream As New System.IO.MemoryStream

    objeto.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
    bitmapBytes = stream.ToArray

    stream.Flush()
    stream.Dispose()

    Dim str1 = Convert.ToBase64String(bitmapBytes)
    Return str1
End Function

And this the android method to create the image:

public static Bitmap GetObjectBitmap(String str) {
    Bitmap bm;

    try {
       byte [] encodeByte=Base64.decode(str.trim(), Base64.DEFAULT);
       bm = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);    
    } catch(Exception e) {
        e.getMessage();
        bm = null;
    }
    return bm;
}

The problem is that the image is displayed in the ImageView with a black background instead of transparent.

Was it helpful?

Solution

You are saving the image in abmp format, but you need to save it in png format instead.

Change the following line from you code

objeto.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)

To this

objeto.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top