我想阅读我的MySQL数据库的Blob 这个“数组”BLOB将被放置在“图库”中。
从数据库中读取BLOB的代码:
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);
}
ComoeufaçosraracolocarváriasBLOBem uma Gallery,qualtransformaçãodevofazer?
答案 0 :(得分:0)
以base64格式存储图像 - 要编码:
Bitmap clickedPhoto;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
clickedPhoto.compress(Bitmap.CompressFormat.JPEG, 100, baos);
String strData = Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
您可以将此strData
存储为数据库中的varchar / text
解码:
byte[] arrPhoto = Base64.decode(strData, Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(arrPhoto, 0, arrPhoto.length);
使用ResultSet中的getString()获取strData
,然后将其解码为要在应用程序中使用的位图。
请告诉我这是否适合您。