Android sqlite數據庫存取圖片信息

Android sqlite數據庫存取圖片信息

存儲圖片:bitmap 

 

 

private byte[] getIconData(Bitmap bitmap){  
    int size = bitmap.getWidth()*bitmap.getHeight()*4;  
    ByteArrayOutputStream out = new ByteArrayOutputStream(size);  
    try {  
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);  
        out.close();  
    } catch (IOException e) {  
        e.printStackTrace();  
    }  
    return out.toByteArray();  
}  

 

 

獲取圖片:

 

 

Bitmap getIconFromCursor(Cursor c, int iconIndex) {  
    byte[] data = c.getBlob(iconIndex);  
    try {  
        return BitmapFactory.decodeByteArray(data, 0, data.length);  
    } catch (Exception e) {  
        return null;  
    }  
}  

 

 

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *