Android 摄像头API捕获的图像在景观中自动保存

Android 摄像头API捕获的图像在景观中自动保存,android,bitmap,camera,rotation,scale,Android,Bitmap,Camera,Rotation,Scale,我正在使用blow post处理摄像头API,并将摄像头翻转到前后。 在三星设备中,默认情况下,它在横向视图中打开相机预览,但 camera.setDisplayOrientation(90); 通过这段代码,我可以打开相机预览的肖像。但是,当我保存图像时,它会自动将其保存在风景中 用这种方法 Matrix matrix = new Matrix(); matrix.postRotate(90); Bitmap bitmap = BitmapFactory.decodeFil

我正在使用blow post处理摄像头API,并将摄像头翻转到前后。

在三星设备中,默认情况下,它在横向视图中打开相机预览,但

camera.setDisplayOrientation(90);
通过这段代码,我可以打开相机预览的肖像。但是,当我保存图像时,它会自动将其保存在风景中

用这种方法

Matrix matrix = new Matrix();
    matrix.postRotate(90);
    Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
    Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
            bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(rotatedBitmap,
            curntViewWidth, curntViewHeight, true);
处理速度变慢了。有没有其他方法可以使相机预览、捕获和保存图像的方向保持一致

我们是否有任何库可以像此应用程序一样打开相机并设置特定大小的图像

来自
摄像机的文档。参数#setRotation()

如果应用程序希望旋转图片以匹配 用户看到的应用程序应使用OrientationEventListener和 摄影机

OrientationEventListener
是一个抽象类,包含
onOrientationChanged()
。此方法将接收来自系统的方向更改。这是一种可能的实现方式:

    OrientationEventListener listener = new OrientationEventListener(this,
            SensorManager.SENSOR_DELAY_NORMAL) {

        @Override
        public void onOrientationChanged(int i) {
           //Code from above goes here.
        }
    };
    listener.enable();

请进一步解释,在哪里写这个onOrientationChanged()方法,如何应用它。你能告诉我在哪里设置这个侦听器吗?如何将它与我的代码联系起来我在上面的回答中已经告诉过你了。创建该类的实例并调用其
enable()
来“注册”它。通过应用它获取“AndroidRuntime(22343):java.lang.RuntimeException:无法获取相机信息”
    OrientationEventListener listener = new OrientationEventListener(this,
            SensorManager.SENSOR_DELAY_NORMAL) {

        @Override
        public void onOrientationChanged(int i) {
           //Code from above goes here.
        }
    };
    listener.enable();