简体   繁体   English

相机预览问题-预览像素化并变形

[英]Camera Preview Issue - Preview becomes pixellated and distorted

I am creating an application, part of which has a camera preview. 我正在创建一个应用程序,其中一部分具有相机预览。

My problem is, if I hit home on the device and re open the app the camera is pixelated with purple lines running through it. 我的问题是,如果我在设备上回家,然后重新打开应用程序,则相机会被紫色像素线像素化。 I had assumed that this was something to do with the onResume() / onPause() methods, but I in this I stop my preview and set the camera to null (below) 我以为这与onResume()/ onPause()方法有关,但是在此我停止了预览并将相机设置为null(下图)

ON RESUME 恢复时

@Override
    public void onResume() {

        //Registering the Listener
        super.onResume();
        manager.registerListener(this,
                manager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                manager.SENSOR_DELAY_NORMAL);

        //Opening the Camera and Starting the Preview
        camera = Camera.open();
        startPreview();
    }

ON PAUSE 暂停时

    @Override
    public void onPause() {

        super.onPause();
        if(camera!=null)
        {
            camera.stopPreview();
            camera.release();
            camera = null;
            inPreview = false;

        }
    }

I have an option for the user to retake their pic, if the user tries to retake the image for a third time I face the same issue. 我有一个供用户重新拍摄照片的选项,如果用户第三次尝试重新拍摄图像,则我会遇到相同的问题。 I don't know what the issue is, I obtained my camera code from 我不知道问题是什么,我从

https://github.com/commonsguy/cw-advandroid/blob/master/Camera/Preview/src/com/commonsware/android/camera/PreviewDemo.java https://github.com/commonsguy/cw-advandroid/blob/master/Camera/Preview/src/com/commonsware/android/camera/PreviewDemo.java

With a little editing to suit my needs. 进行一些编辑以满足我的需要。

From reading and research it seems that my onPause and onResume are correct so this may not be the problem... 从阅读和研究来看,我的onPause和onResume似乎是正确的,所以这可能不是问题...

Any help is appreciated 任何帮助表示赞赏

if anyone like me (learning the ropes) comes across this same issue, what my problem was I had added 如果像我这样的人(学习绳索)遇到相同的问题,那么我添加的问题是什么

camera.setDisplayOrientation(90);

in order to rotate the preview to portrait. 为了将预览旋转为纵向。 My problem was, I had called this in the wrong place, I now call it in the onResume() method. 我的问题是,我在错误的地方调用了它,现在我在onResume()方法中调用了它。

A simple fix in the end...thanks everyone 最后的简单修复...感谢大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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