Displaying image from the sqlite database using cursor in android

First of all please did not store the images in database because sqlite will not support more then 1 mb,i may be wrong, images should be store in assets or drawble folder and the name of images should be store in database then you can get it from name to resource conversion by code

 String videoFileName= c.getString(c.getColumnIndex(TB_SETTING_VIDEOFILENAME));
        int dot = videoFileName.lastIndexOf(".");
        videoFileName=videoFileName.substring(0,dot);
        Log.d("VIDEOFILENAME", videoFileName);

        int videoFileRId = getResources().getIdentifier(videoFileName , "raw", getPackageName());   

I hope this will help you.


I've tried to use Stream instead of byte array, mine example simply works for me. Also try to use Cursor.getColumnIndex()

    byte[] blob = c.getBlob(c.getColumnIndex(YourDB.IMAGE));
    ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

Here's my "create table" statement, pls double check yours

    create table datatable(_id INTEGER PRIMARY KEY AUTOINCREMENT, image BLOB, price INTEGER);