1

I want to click image from camera of my phone and then save this image in sqlite Database which is stored in sdcard.plz tell me How I can do this??following is the code I have written for clicking Image

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        File file = new File(Environment.getExternalStorageDirectory(), bb);

        outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PICTURE);
Sangeeta Rawat
  • 199
  • 1
  • 1
  • 15

1 Answers1

1

Give Permission in manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>

File destination = new   File(Environment.getExternalStorageDirectory(),"image.jpg");
 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
 startActivityForResult(intent, CAMERA_PICTURE);

then override onActivityResult gat image file from destination image it convert into bitmap and save this. then convert it into byte array

 @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data){
        if(requestCode == CAMERA_PICTURE && resultCode == Activity.RESULT_OK) {
               realImageStr = new String("");
             try {
        FileInputStream in = new FileInputStream(destination);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 10; //Downsample 10x
            Log.d("PP", " bitmap factory=========="+options);
            Bitmap user_picture_bmp = BitmapFactory.decodeStream(in, null, options);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            user_picture_bmp.compress(Bitmap.CompressFormat.PNG, 100, bos);
            byte[] bArray = bos.toByteArray();
        } catch (Exception e) 
        {
        } }}

When you will save into byte type then save in to database ur byteCode in image coloumn and image column data type is BLOB type.

Yogendra
  • 4,817
  • 1
  • 28
  • 21