Android How to save camera images in database and display another activity in list view?

后端 未结 3 1621
情歌与酒
情歌与酒 2020-12-01 10:16

i am using camera to take photos and want to store in database(SQLite). Stored photos have to be displayed in the another activity with list view like this list view images

3条回答
  •  旧时难觅i
    2020-12-01 10:33

    Create DataBase helper class like this..

    On Capturing the image insert the image by converting into bytes:

    Imagehelper help=new Imagehelper(this);
    
        if (requestCode == CAMERA_REQUEST) {  
                            Bitmap photo = (Bitmap) data.getExtras().get("data");   
                            imageView.setImageBitmap(photo);
                            ByteArrayOutputStream stream = new ByteArrayOutputStream();
                            photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
                            byte[] byteArray = stream.toByteArray();
    
                            help.insert(byteArray);
        }
    

    To retrieve Form the Database:

    Imagehelper help=new Imagehelper(this);
    
           Cursor c= help.getAll();
           int i=0;
           if(c.getCount()>0)
           {  
               Bitmap[]  array=new Bitmap[c.getCount()];
               c.moveToFirst();
               while(c.isAfterLast()==false)
               {
    
                   byte[] bytes=c.getBlob(c.getColumnIndex("imageblob"));
    
                array[i]=BitmapFactory.decodeByteArray(bytes, 0, 0);
                c.moveToNext();
                i++;
                }
               Log.e("Bitmap length",""+array.length);
           }
    

    Pass this Bitmap array to ListView

提交回复
热议问题