I save the image to an xml file. For this, I initially convert the Bitmap into a byte array.

Bitmap bitmapSave = MediaStore.Images.Media.getBitmap(getContentResolver(), uriSave); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmapSave.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] b = stream.toByteArray(); 

Then I pound this array into a line and get the following value: [B@59710c4

 `org.w3c.dom.Element photo = doc.createElement("photo"); photo.appendChild(doc.createTextNode(b.toString())); photosElement.appendChild(photo); stream.close(); 

Then I save this xml file to a folder, etc.

And now loading: I receive value which I received from byte array, I receive everything as it should [B@59710c4

 String strLoad = elementsLoad.get(i).text(); 

Next I get to the array from byte's string

 byte[] imgBytes = strLoad.getBytes(); 

It would seem that everything, but the problem is that the array is very small compared to the original one, and when I get a Bitmap and assign it to an ImageView, the ImageView turns white. Ie assigned a white picture.

 Bitmap bitmap = BitmapFactory.decodeByteArray(imgBytes, 100, imgBytes.length); 
  • This is not about what interests you? .. - Alekcvp
  • And now this moment, about the meaning of [B@59710c4 . In general, I would recommend in xml to save an encoded base64 array of bytes, if you really really need. And ideally, do not store binary data in text format. - Alekcvp

1 answer 1

In general, if you take the squeeze from my comments, the answer is:

  1. photo.appendChild(doc.createTextNode(b.toString()));
    b.toString(); does not convert an array of bytes to a string, but converts an array of bytes into a string. Those. the value of [B@59710c4 , which you received, means: "an array of bytes at the address 0x59710c4", which is meaningless to save to a file, as you understand.
  2. To save your array to a file, use Base64.encodeToString(b, Base64.NO_WRAP) .
  3. Accordingly, when loading, use byte[] imgBytes = Base64.decode(strLoad, Base64.NO_WRAP);

PS: Base64