how to save image in sqllite database?

后端 未结 3 922
囚心锁ツ
囚心锁ツ 2021-01-28 05:11

this is my code below which browse imagew gellery and pick image but how do insert image view in database? this code sucessfuly show on screen selected image but not store in da

3条回答
  •  半阙折子戏
    2021-01-28 05:57

    First make field in sqlite as blob datatype

    than get byte and store in databse image.getBytes();

    or if you have bitmap than convert into byte array

    and store into database

     public static byte[] getBitmapAsByteArray(Bitmap bitmap, boolean type) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        if (type) {
            bitmap.compress(CompressFormat.PNG, 0, outputStream);
        } else {
            bitmap.compress(CompressFormat.JPEG, 0, outputStream);
        }
        return outputStream.toByteArray();
    }
    

提交回复
热议问题