How to save bitmap in database?

前端 未结 4 1377
抹茶落季
抹茶落季 2021-02-02 02:46

I want to know how to save a bitmap in database. I created table in db as:

@Override
public void onCreate(SQLiteDatabase db)
{
    db.execSQL(\"CREATE TABLE \" +         


        
4条回答
  •  故里飘歌
    2021-02-02 03:25

    Try this one

    InputStream is = mycon.getAssets().open("data/Images/img1");
                    if (is.available() == -1) {
                        Log.v(null, "Images not read to Input stream");
                    }
                    if (is != null) {
                        BufferedInputStream bis = new BufferedInputStream(is, 128);
                        ByteArrayBuffer barb = new ByteArrayBuffer(128);
                        // read the bytes one by one and append it into the
                        // ByteArrayBuffer barb
                        int current = 0;
                        while ((current = bis.read()) != -1) {
                            barb.append((byte) current);
                        }
                        values.put("imageData", barb.toByteArray());
    

提交回复
热议问题