Bitmap in byte, byte in string, string in byte and byte in Bitmap. General preservation of the image



  • I keep the image in the xml file, which is why I turn Bitmap into 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();
    

    Next, I'm putting this mass in line, and I meaning it: [B@59710c4

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

    I keep this xml file in the folder. ♪

    And now load: I get the value that I got from the byte array, I get it all right. [B@59710c4

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

    Next, I get in a row byte's

    byte[] imgBytes = strLoad.getBytes();
    

    I think that's all, but the problem is that the mass compared to the original is very small, and when I get Bitmap and assign it to ImageView, ImageView becomes white. That's a white painting.

    Bitmap bitmap = BitmapFactory.decodeByteArray(imgBytes, 100, imgBytes.length);
    


  • Anyway, if you're gonna take a squeeze from my comments, the answer is,

    1. photo.appendChild(doc.createTextNode(b.toString()));
      b.toString(); doesn't transform the bikes into a line, but transforms it into a line. object a set of bikes. Me. meaning [B@59710c4Which you received means "massistant bikes at 0x59710c4" to keep in the file, as you understand, meaningless.
    2. To keep your file, you need to use your mass. Base64.encodeToString(b, Base64.NO_WRAP)
    3. Accordingly, use it for loading byte[] imgBytes = Base64.decode(strLoad, Base64.NO_WRAP);

    P.S: https://developer.android.com/reference/android/util/Base64.html




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2