mercredi 27 janvier 2016

Unable to retrieve image from SQLite. SKImageDecoder::Factory returned null

Currently I'm developing an apps which involves capture, save and retrieve image from SQLite. I managed to capture and save image into SQLite. However, I cannot retrieve the image back. I converted the image into byte array before saved it inside SQLite. This is my coding:

Database.java

public String displayImageBendaOne(String rowId){
    SQLiteDatabase db=helper.getReadableDatabase();

    Cursor cursor = db.query(true, BacaHelper.TABLE_NAME_BENDA, new String[] {BacaHelper.UID,
                    BacaHelper.BENDA, BacaHelper.BENDA_IMAGE, BacaHelper.BENDA_ID}, BacaHelper.BENDA_ID + "==" + rowId, null,
            null, null, null, null);
    StringBuffer buffer= new StringBuffer();

    if (cursor.moveToFirst()) {
        {
            //byte[] bImageOne=cursor.getBlob(cursor.getColumnIndex(BacaHelper.BENDA_IMAGE));
            byte[] bImageOne = cursor.getBlob(1);
            buffer.append(bImageOne);
        }
    }
    db.close();
    return buffer.toString();
}

Baca.java

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.benda_read);
        bacaHelper= new BacaDatabaseAdapter(this);
        bIOne = (ImageView) findViewById(R.id.imageOne);

        passVar = getIntent().getStringExtra(benda.ID_EXTRA);
        String bendaIOne = bacaHelper.displayImageBendaOne(passVar);
        Log.e("Byte[] ", bendaIOne);

        ByteArrayInputStream imageStream = new ByteArrayInputStream(bendaIOne.getBytes());
        theImage = BitmapFactory.decodeStream(imageStream);
        imageStream.reset();
        bIOne.setImageBitmap(theImage);
    }

There are no syntax error at the moment but when I run my apps, the image does not appear. In logcat showed SKImageDecoder:: Factory returned null. What is the meaning of this statement? There is something about above coding I cannot figure out. I decided to convert from image to byte array to string to byte array to image. Which is a long process because I don't know how to directly retrieve value of byte array from database. Can anyone point out what I should do? Thanks in advanced.

Aucun commentaire:

Enregistrer un commentaire