簡體   English   中英

將BLOB加載到Gallery Android

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM