0

I found these two part of code, to how to take a photo from the camera in Android:

Inside the onCreate() method:

        Button capture;

        capture.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
            }
        });

And

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");

    }
}

And it works, but the problem is that, the quality of the result image is very low! I like to know how can I specify what quality of image I want to take?

Also like to know, are there other options that bitmap to store or work on images?

EDIT:

This is what I see before pushing the capture button: enter image description here

And this is what it takes after pushing the capture button(it reduces the quality): enter image description here

I must say, when I take photos with my phone(outside of this app I mean) it works good, but inside the my written app, it reduces the taken image quality!

**Also I have another question...how can I remove this second page that shows after it took the image(the page shows RETRY-OK options I mean).

Hasani
  • 3,543
  • 14
  • 65
  • 125
  • If the intent returns `"data"`, it is a tiny thumbnail, not the full image: see https://stackoverflow.com/a/41344412/192373 which accounts for requirements of Android 7 and higher. – Alex Cohn Mar 12 '18 at 10:13

1 Answers1

1

Check below solution for your problem.

 public static File IMAGE_PATH = null;
     public static final int CAMERA_REQUEST = 100;
         private void openCameraApp(Context mContext) {
            Intent picIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);


            String file_path = Environment.getExternalStorageDirectory().toString() +
                    "/" + mContext.getResources().getString(R.string.app_name);

            File dir = new File(file_path);
            if (!dir.exists())
                dir.mkdirs();
            IMAGE_PATH = new File(dir, mContext.getResources().getString(R.string.app_name) +  System.currentTimeMillis() + ".png");


            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                picIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(mContext, mContext.getPackageName()+".fileprovider", IMAGE_PATH));
            }
            else {
                picIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(IMAGE_PATH));
            }

            ((Activity) mContext).startActivityForResult(picIntent, CAMERA_REQUEST);

        }
kishna.147
  • 167
  • 8
  • You say I must save the image to get the better result? – Hasani Mar 12 '18 at 10:17
  • Yes, you must save the image to get better quality image. But, if you dont want image to be saved then hold the image path till the time your task related to image gets completed, after that delete the image by using image path – kishna.147 Mar 12 '18 at 10:23
  • I have added a new question a the end of my post, do you know about it? – Hasani Mar 12 '18 at 10:32
  • You can not remove the image preview screen, as it is inbuilt camera functionality and we cant override it programmatically. – kishna.147 Mar 12 '18 at 10:47
  • But I see in other apps, when I take a photo they don't show this page – Hasani Mar 12 '18 at 11:32
  • Preview of Captured Image will not come, in case when custom camera implemented in the application. It like developing own camera app and perform all functionalities with this app. – kishna.147 Mar 12 '18 at 11:37
  • Thank you Kishna...I will accept your answer after some days. – Hasani Mar 12 '18 at 11:47
  • @user3486308 welcome, hope it helped you – kishna.147 Mar 12 '18 at 11:51