【问题标题】:Android change rotation during Camera Intent image capture and not afterAndroid 在 Camera Intent 图像捕获期间而不是之后更改旋转
【发布时间】:2017-07-28 00:52:18
【问题描述】:

我正在打开相机并拍照。 这是我的代码:

private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            // Create the File where the photo should go
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
                // Error occurred while creating the File

            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                Uri photoURI = FileProvider.getUriForFile(this,
                        "com.example.android.fileprovider",
                        photoFile);
                takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivity(takePictureIntent);

            }
        }
    }



    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );

        // Save a file: path for use with ACTION_VIEW intents
        mCurrentPhotoPath.add(image.getAbsolutePath()) ;
        return image;
    }

}

现在的问题是当使用意图打开相机时,相机会在模拟器的横向视图中打开。这是图片:

The Camera view is open 现在我拍了一张照片后,它的样子。

After Image capture

在这个阶段,没有必要旋转图像,因为图像已经被切断了...... 如何确保Android相机将正确保存图像的想法...... 顺便说一句...无论我的应用程序如何,如果我在模拟器上打开相机应用程序,它首先会执行相同的操作,相机视图会覆盖整个屏幕,但是当单击按钮时,图像会被切断...

【问题讨论】:

    标签: android android-camera


    【解决方案1】:

    在这个阶段没有必要旋转图像,因为图像已经被切断了

    这不太可能,但我不能排除它。将保存的图像下载到您的开发机器并在那里检查。

    如何确保 android 相机正确保存图像的想法

    你没有。您将拍照委托给了数百个可能的相机应用程序之一。这些相机应用程序中的每一个都将执行其开发人员决定让它执行的任何操作。没有一个是没有错误的。并且没有可以传入ACTION_IMAGE_CAPTURE 的EXTRA_PLEASE_DO_NOT_HAVE_BUGS 值。

    如果您想获得更多控制权,请使用相机 API 或围绕这些 API 的第三方库包装器将拍照功能直接添加到您的应用中。

    【讨论】:

      猜你喜欢
      • 2021-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多