从相机保存照片时,图像质量下降

问题描述 投票:0回答:0

调用相机的代码

    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);
                                }

保存图片的代码

    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();
        }
    }

图像存储在图库中,但质量很差。

我在压缩参数和格式中尝试了不同的质量值,但没有帮助

我收到的图像有 187x250 的扩展
The image I receive has an extension of 187x250

java android android-camera save-image
© www.soinside.com 2019 - 2024. All rights reserved.