Android 取出 图片以字节形式存放到数据库的数据,并将图片显示


            Cursor cursor = DatabaseManger.getInstance(getContext())
                    .queryData2Cursor("SELECT * FROM TB_PICTURE WHERE vc_id = '"+id+"'",
                            null);
            if(cursor != null && cursor.getCount() > 0){
                while (cursor.moveToNext())
                {
                   
                    byte[] imagequery = cursor.getBlob(cursor.getColumnIndex("VC_SRC"));
                    Bitmap imagebitmap = stringToBitmap(imagequery);
                    String id = cursor.getString(cursor.getColumnIndex("VC_ID"));
                    String pid = cursor.getString(cursor.getColumnIndex("VC_PID"));
                    String name = cursor.getString(cursor.getColumnIndex("VC_NAME"));
                    //iv.setImageBitmap()//图片控件赋值
                    
                }
                cursor.close();
            }


public Bitmap stringToBitmap(byte[] string) {
        Bitmap bitmap = null;
        try {
//base64转字节数组
            byte[] bitmapArray = Base64.decode(string, Base64.DEFAULT);
            bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bitmap;
    }

 

你可能感兴趣的:(android,android,cursor)