"android how to save camera images in database and display another activity in list view?" Code Answer

2

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

By user3728064 on March 18 2022

Answers related to “android how to save camera images in database and display another activity in list view?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.