walidroid
walidroid

Reputation: 109

low quality when capture picture and send it image view

low quality when capture picture and send it image view when imgCamera button pressed

    case R.id.imgCamera:
                    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(cameraIntent, CAMERA_REQUEST);

                    break;

**the activity result :**

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case CAMERA_REQUEST:
                    mPhotoEditor.clearAllViews();
                    Bitmap photo = (Bitmap) data.getExtras().get("data");
                    mPhotoEditorView.getSource().setImageBitmap(photo);
                    break;
                case PICK_REQUEST:
                    try {
                        mPhotoEditor.clearAllViews();
                        Uri uri = data.getData();
                        Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                        mPhotoEditorView.getSource().setImageBitmap(bitmap);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    break;
            }
        }
    }

please help me I want to get the best quality for the picture captured

Upvotes: 1

Views: 763

Answers (2)

John Lord
John Lord

Reputation: 2185

my comment tells you want is wrong. Here's the solution:

first, modify your camera intent:

        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        _photoUri = createImageUri();
        // Continue only if the File was successfully created
        if (_photoUri != null) {
            //setflags is required to clear flag_activity_new_task that is automatically set on
            //direct calls.  If not cleared, you get instant returns from the app.
            takePictureIntent.setFlags(0);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, _photoUri);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
 private Uri createImageUri() {
    return FileProvider.getUriForFile(this
            , this.getApplicationContext().getPackageName()
            , new File(Environment.getExternalStorageDirectory()
                    , "orderphoto.jpg"));
}

this tells the camera where to put the photo.

check in your activity result for RESULT_OK to ensure they didn't cancel.

You'll need to then be able to read from the file system. Here's how our app does it: Note i can't be positive i'm not referencing a custom function in this. YMMV.

    private Bitmap DecodeFile(Uri fileUri) {
    /* There isn't enough memory to open up more than a couple camera photos */
    /* So pre-scale the target _bitmap into which the file is decoded */

    /* Get the size of the ImageView */
    int targetW = _imageView.getWidth();
    int targetH = _imageView.getHeight();

    /* Get the size of the image */
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(fileUri.getPath(), bmOptions);
    // TODO: 2/25/2019 Update to BitmapFactory.decodeStream()

    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;

    if (photoW == 0 || photoH == 0) {
        AppUtility.ShowToast("BitmapFactory.Decode: File Decoding Failed!");
    }

    /* Figure out which way needs to be reduced less */
    int scaleFactor = 1;
    if ((targetW > 0) || (targetH > 0)) {
        scaleFactor = Math.min(photoW/targetW, photoH/targetH);
    }

    /* Set _bitmap options to scale the image decode target */
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;

    /* compress/shrink the bitmap */
    // TODO: 2/25/2019 Update to BitmapFactory.decodeStream()
    return BitmapFactory.decodeFile(fileUri.getPath(), bmOptions);
}

When you use this, it does all the hard work for you and sizes it to the screen. Note that some samsung devices lie about the orientation so you may have problems about that.

Upvotes: 1

MustafaKhaled
MustafaKhaled

Reputation: 1489

To save the full-size image you need to do much more stuff.

data.getData();

This would return image thumbnail which is a low-quality image for the original one. I can't find an accurate guide than the official documentation. check this link from Android Developer documentation. Following it, you would save the high-quality image easily instead of a low-quality one. Not to mention, You would learn about FileProivder and storage (Maybe you like to save it internal storage or external storage).

Be patient .. happy coding

Upvotes: 2

Related Questions