Bytes to Base64 String and convert Base64 String to Bitmap returns NULL

Viewed 27

In the drawable folder I have an image us.jpg and I want to set this image (bitmap) in a String, it returns android.graphics.Bitmap@a5e4fb9 USA as a result. I want the flag of the USA to stand next to the name of the country. Can you help and thanks in advance!

    Resources resources = this.getResources();
    Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.us);
    ByteArrayOutputStream image = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, image);
    byte[] b = image.toByteArray();
    encodeImage = Base64.encodeToString(b, Base64. DEFAULT);
    byte[] decodeString = Base64.decode(encodeImage, Base64. DEFAULT);
    decodeByte = BitmapFactory.decodeByteArray(decodeString, 0, decodeString.length);

    // this is the string for the AlertDialog from which listItems is called
    // and from where the country can be selected
    final String[] listItems = { decodeByte + " " + "USA" };
0 Answers
Related