从Android中的相机捕获后如何获取高质量的位图图像?

时间:2019-03-14 15:56:24

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

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

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

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

1 个答案:

答案 0 :(得分:1)

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

请注意,届时图片已在设备MediaStore中索引,也就是。画廊。

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

相关问题