Amrmsmb
Amrmsmb

Reputation: 11416

Camera.open() is not available/accessible?

i'm trying to create cameraPreview, and I found in the below code "Camera.open()"

this method is not accessible or not available to me, there no such method the Object Camera

can have access to.

Is there any thing i should do, or it's amistake inthe tutorial?

Java Code:

@Override
    public void surfaceCreated(SurfaceHolder holder) 
    {
            try
            {
                    //Open the Camera in preview mode
                    this.camera = Camera.open();
                    this.camera.setPreviewDisplay(this.holder);
            }
            catch(IOException ioe)
            {
                    ioe.printStackTrace(System.out);
            }
    }

Upvotes: 1

Views: 1414

Answers (2)

Md Abdul Gafur
Md Abdul Gafur

Reputation: 6201

Here is complete Camera view class ::

class Preview extends SurfaceView implements SurfaceHolder.Callback {
private static final String TAG = "Preview";
SurfaceHolder mHolder;
public Camera camera;

Preview(Context context) {
    super(context);
    mHolder = getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

}

public void surfaceCreated(SurfaceHolder holder) {
    camera = Camera.open();
    camera.setDisplayOrientation(90);
    try {
        camera.setPreviewDisplay(holder);
        camera.setPreviewCallback(new PreviewCallback() {

            public void onPreviewFrame(byte[] data, Camera camera) {
                Log.d(TAG, "onPreviewFrame called at: "
                        + System.currentTimeMillis());
                Preview.this.invalidate();
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}

public void surfaceDestroyed(SurfaceHolder holder) {
    camera.release();
    camera = null;
}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    camera.startPreview();
}

}

Upvotes: 1

user658042
user658042

Reputation:

You most likely imported the wrong camera class at the top of your source file, which is android.graphics.Camera.

You need android.hardware.Camera instead.

Upvotes: 5

Related Questions