Frage

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)

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

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...

Any help is appreciated

War es hilfreich?

Lösung

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.

A simple fix in the end...thanks everyone

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top