预览画面镜像效果如何解决Android

How can mirror effect be solved on preview screen Android

早些时候我 运行 我的代码遇到了一个问题,当我使用前置摄像头拍摄照片时,当将图片设置为 ImageView 时,旋转被翻转并且图像使用镜像效果。

经过一番研究,问题已解决,但我仍然遇到图像在预览屏幕上翻转的问题。

开始 activity 结果..(用户看到相机)

用户拍照(显示预览画面,这里是我看到的镜像效果)

用户单击确定.. ImageView 已设置.. 这里图像设置完美,镜像效果没有问题

下面是我的代码..

    private void takePhoto(){
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        uri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, 100);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == 100) {
            if (resultCode == RESULT_OK) {

                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 8;

                Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath(),
                        options);

                Matrix matrix = new Matrix();

                float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1};
                Matrix matrixMirrorY = new Matrix();
                matrixMirrorY.setValues(mirrorY);

                matrix.postConcat(matrixMirrorY);

                ExifInterface exifInterface = null;
                try {
                    exifInterface = new ExifInterface(uri.getPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                assert exifInterface != null;
                int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);

                switch (orientation) {
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        matrix.setRotate(90);
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        matrix.setRotate(180);
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        matrix.setRotate(270);
                        break;

                }
                rotatedBitmap = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
                visitorImage.setImageBitmap(rotatedBitmap);
                visitorPreviewImage.setImageBitmap(rotatedBitmap);

            } else if (resultCode == RESULT_CANCELED) {
                // user cancelled Image capture
                Toast.makeText(getApplicationContext(),
                        "User cancelled image capture", Toast.LENGTH_SHORT)
                        .show();
            } else {
                // failed to capture image
                Toast.makeText(getApplicationContext(),
                        "Sorry! Failed to capture image", Toast.LENGTH_SHORT)
                        .show();
            }

        }
    }

我的问题是我目前不确定在哪里可以解决预览屏幕的镜像效果问题。

谢谢大家。

My issue is i am currently unsure where i can fix the issue with mirror effect for preview screen

预览屏幕在另一个 Android 应用程序中,而不是您的应用程序。 "fix" 没有你的事。相机应用会根据相机应用的需要显示其预览。