0

I would like to read a Blob of my MySQL database This "Array" BLOB would be placed in a "Gallery".

Code to read BLOB from the database:

while (rs.next()) {
            String id = rs.getString("id");
            String description = rs.getString("description");
            Blob image = (Blob) rs.getBlob("img");

            Material m = new Material(id, description,image);
            listaMaterial.add(m);
}

Como eu faço para colocar várias BLOB em uma Gallery, qual transformação devo fazer?

1 Answers1

0

To store images in base64 format - To Encode :

Bitmap clickedPhoto;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
clickedPhoto.compress(Bitmap.CompressFormat.JPEG, 100, baos);
String strData = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);

You can store this strData as a varchar/text in your database

To Decode:

byte[] arrPhoto = Base64.decode(strData, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(arrPhoto, 0, arrPhoto.length);

Get strData by using getString() from your ResultSet and then decode it to a Bitmap to use in your application.

Let me know if this works for you.

Aakash
  • 1,860
  • 19
  • 30