0

Code to call the camera

    if (checkSelfPermission(Manifest.permission.CAMERA) ==
                                        PackageManager.PERMISSION_GRANTED) {
                                    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                    cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
                                    imagePickerLauncher.launch(cameraIntent);
                                }

The code that saves the image

    private void saveImage(Bitmap bitmap) {
        File imagesFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyApp");
        if (!imagesFolder.exists()) {
            imagesFolder.mkdirs();
        }
        String fileName = "MyImage_" + System.currentTimeMillis() + ".jpg";
        File image = new File(imagesFolder, fileName);
        try {
            FileOutputStream fos = new FileOutputStream(image);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            options.inSampleSize = calculateInSampleSize(bitmap.getWidth(), bitmap.getHeight(), 1080, 1920);
            Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth()/options.inSampleSize, bitmap.getHeight()/options.inSampleSize, true);
            if (resizedBitmap != null) {
                resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);

            }
            fos.close();
            MediaScannerConnection.scanFile(this,
                    new String[] { image.getAbsolutePath() },
                    null,
                    new MediaScannerConnection.OnScanCompletedListener() {
                        public void onScanCompleted(String path, Uri uri) {
                            Log.i("ExternalStorage", "Scanned " + path + ":");
                            Log.i("ExternalStorage", "-> uri=" + uri);
                        }
                    });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

The image is stored in the gallery but in very poor quality.

I experimented with different quality values ​​in the compress argument and format but it didn't help

The image I receive has an extension of 187x250
The image I receive has an extension of 187x250

Thomas
  • 87,414
  • 12
  • 119
  • 157
Mr_JEY
  • 1
  • 1
  • You seem to be resizing and compressing the image, no wonder the quality deteriorates. Btw, it might help if you'd provide some example of how much it deteriorates, e.g. an original image (along with infos like format and dimensions) and an image resulting from your code. – Thomas Mar 28 '23 at 06:28
  • @Thomas I edited my question with a link to the image I get I will also give a link to a photo I took on the standard camera application https://drive.google.com/file/d/1q9ICBQRtQYxlPqFORFpkLBrCAQvl0KSf/view?usp=share_link – Mr_JEY Mar 28 '23 at 06:46
  • Does this answer your question? [Android Camera Intent: how to get full sized photo?](https://stackoverflow.com/questions/6448856/android-camera-intent-how-to-get-full-sized-photo) – Dalija Prasnikar Mar 28 '23 at 06:51
  • I don't see any quality issues in that 187x250px image. Of course your camera would be able to capture more details and smoother edges but for that small size it looks fine. – Thomas Mar 28 '23 at 07:09
  • @Thomas in the gallery, the image is displayed with really poor quality and, by the way, it does not allow zooming, that is, neither reducing nor increasing, on the screen of my phone (I think and not only on mine) it looks like pixel art – Mr_JEY Mar 28 '23 at 07:37
  • @Thomas I need an image in higher magnification and with normal quality So it looks as if it is good for its extension, but still, this result does not suit me – Mr_JEY Mar 28 '23 at 07:47
  • I'm still not sure I understand your problem so let me try to rephrase: 1) you're taking an image captured by the camera which has a higher resolution, 2) you're resizing the image to be smaller (like your 187x250 example) 3) you're displaying that resized image full screen on a phone which normally has a HD screen, right? If that's the case then yes, the image will look very pixelated as step 2 loses a lot of image information - so resize to a resolution closer to HD. – Thomas Mar 28 '23 at 09:45

0 Answers0