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

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

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

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

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

android android-camera android-camera-intent bitmapimage
1个回答
1
投票

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

请注意,到那时,图片已在设备MediaStore中编入索引,a.k a。画廊。

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

© www.soinside.com 2019 - 2024. All rights reserved.