Android-sqlite数据库存取图片信息

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;

        }

    }

posted @ 2011-06-05 14:11  silencer  阅读(2373)  评论(0编辑  收藏  举报