tags:

views:

33

answers:

1

Hello

Here I write camera snapshot on the db.

 `private SQLiteDatabase db;
// SOME CODE HERE ///
InputStream is =new ByteArrayInputStream(data);
BufferedInputStream bis = new BufferedInputStream(is,128);
ByteArrayBuffer baf = new ByteArrayBuffer(128);
int current = 0;
while ((current = bis.read()) != -1) {
     baf.append((byte) current);
}
baf.toByteArray();
ContentValues initialValues = new ContentValues();
initialValues.put("mapimg", baf.toByteArray();
db.insert(DATABASE_TABLE, null, initialValues);

` This writes correctly in the db a new row.

When I try to show the image :

DbUtil db = new DbUtil(this);
List<Row> rows = db.fetchAllRows();
db.close();
byte[] imageByteArray= rows.get(10).getMapimg();
ByteArrayInputStream imageStream = new ByteArrayInputStream(imageByteArray);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
ImageView imageView ;
imageView = (ImageView)findViewById(R.id.ImageView01);
imageView.setImageBitmap(theImage);

In the xml :

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    >


   <ImageView
         android:id="@+id/ImageView01"
        android:layout_width="300px"
        android:layout_height="300px"
        android:scaleType="center"
         />



</LinearLayout>

But no image appears on screen. Where is the problem ?

A: 

Could be number of things. Do this:

  1. Check the log for ERRORs.
  2. Check that you get the same data from database that you put in. Check size. Use insertOrThrow() instead of insert().
  3. Check that BitmapFactory.decodeStream(..) does not return null.
Peter Knego
The problem is that BitmapFactory.decodeStream(..) return null.
carnauser
So there is something wrong with data stream. Try reading it from database, then writing it to file and opening it on your computer.
Peter Knego