【问题标题】:How to get Good Quality Bitmap image after capture from camera in Android?从 Android 中的相机捕获后如何获得高质量的位图图像?
【发布时间】:2019-03-14 15:56:23
【问题描述】:

我试图在从相机捕获图像后获取位图图像。我首先要做的是将图像保存到内存中,然后从图像路径中获取位图图像。

private String imageFilePath =null;
    private void openCameraIntent() {
                Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if(pictureIntent.resolveActivity(getPackageManager()) != null){
                    File photoFile = null;
                    try {
                        photoFile = createImageFile();
                    } catch (IOException ex) {

                    }
                    if (photoFile != null) {
                         photoURI = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID +".fileprovider", photoFile);
                         pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                        startActivityForResult(pictureIntent, REQUEST_CAPTURE_IMAGE);
                    }
                }
            }

        private File createImageFile() throws IOException {
                String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
                                Locale.getDefault()).format(new Date());
                String imageFileName = "IMG_" + timeStamp + "_";
                File storg =
                        getExternalFilesDir(Environment.DIRECTORY_PICTURES);
                File image = File.createTempFile(
                        imageFileName,  /* prefix */
                        ".jpg",         /* suffix */
                        storg      /* directory */
                );

                imageFilePath = image.getAbsolutePath();
                return image;
            }

public Bitmap bitmapimage(String path) {
        return BitmapFactory.decodeFile(path);
    }

但就我而言,我不想将图像保存到内存中。我想在捕获图像后获取位图图像。我试过了,但我得到的图像质量非常低。如何在不保存到内存的情况下获得高质量的位图图像。请帮我这样做。谢谢

【问题讨论】:

    标签: android android-camera android-camera-intent bitmapimage


    【解决方案1】:

    确实如此。相机意图只能将高分辨率图像作为文件传递。您可以在您的应用恢复控制后立即删除它,即使它通常在 onActivityResult() 回调中完成。

    请注意,到那时,图片已在设备 MediaStore 中建立索引,a.k a.图库。

    替代方法是使用相机 API 而不是意图。一些包装库,例如 fotoapparat,可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-12-14
      • 2021-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多