[英]Load BLOB to Gallery android
我想读取我的MySQL数据库的Blob。此“ Array” BLOB将放置在“ Gallery”中。
从数据库读取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);
}
在Colo eufaçopara colocarváriasBLOB em uma画廊中,您对质量的转换感到满意吗?
以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
,然后将其解码为要在应用程序中使用的位图。
让我知道这是否适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.