简体   繁体   中英

Camera Preview upside down

Front Camera is displaying upside down. I am reading each frame. I think i know where to put the code.In surfaceChanged but don't know how to do.

@Override
    public void surfaceChanged(SurfaceHolder mHolder, int arg1 , int arg2 , int arg3)
    {
        if (mHolder.getSurface() == null) { return; }

        mCamera.setPreviewCallback(previewCallback); 

        try
        {
            mCamera.setPreviewDisplay(mHolder);
            mCamera.startPreview();

            return;
        }
        catch (Exception exception)
        {
            Log.d("CameraView", (new StringBuilder()).append("Error starting camera preview: ")
                    .append(exception.getMessage()).toString());
        }
    }

What have i tried.

private android.hardware.Camera.PreviewCallback previewCallback = new android.hardware.Camera.PreviewCallback()
    {
        public void onPreviewFrame(byte abyte0[] , Camera camera)
        {       
            int[] rgbData = YuvUtils.decodeGreyscale(abyte0, widthPreview,heightPreview);

            editedBitmap.setPixels(rgbData, 0, widthPreview, 0, 0, widthPreview, heightPreview);

            if(MainActivity2.cameraId==CameraInfo.CAMERA_FACING_FRONT)  // it is rotating my CameraPreview continuosly.
            {
                matrix.postRotate(270F);
            }
            finalBitmap = Bitmap.createBitmap(editedBitmap, 0, 0, widthPreview, heightPreview, matrix, true);

            if(saveCurrentFrame)
            {
                saveCurrentFrame =false;

                new BitmapSaver(ctx, finalBitmap).start();
            }
        }
    };

But it is continuosly rotating my Camera preview. And my Activity is set to Potrait . No orientation changing is allowed in my Activity

I would use matrix.setRotate() .

matrix.postRotate() adds on the rotate every time it gets called. Angles go from 270 -> 540 -> 810 -> 1080 -> 1350 -> etc.

matrix.setRotate() would always set it to 270.

拍摄照片之前,可以使用_camera.SetDisplayOrientation(90)旋转相机的预览。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM