Code example for Camera

Methods: getParameterssetParameterssetPreviewTexturestartPreview

0
        // Open the camera 
        openCamera(width, height);
 
        // Start the camera 
        mStartCaptureTime = SystemClock.elapsedRealtime();
        mCamera.startPreview();
        mIsOpen = true;
    } 
 
    public void getCurrentFrame() { 
        if (checkNewFrame()) { 
            if (mStartCaptureTime > 0 && SystemClock.elapsedRealtime() - mStartCaptureTime > 2000) {
                // Lock white-balance and exposure for effects 
                Log.i("CC", "Locking white-balance and exposure!");
                Camera.Parameters params = mCamera.getParameters();
                params.setAutoWhiteBalanceLock(true);
                params.setAutoExposureLock(true);
                //mCamera.setParameters(params); 
                mStartCaptureTime = 0;
            } 
 
            mSurfaceTexture.updateTexImage();
            mSurfaceTexture.getTransformMatrix(mCameraTransform);
 
            // display it here 
        } 
    } 
 
    public synchronized boolean hasNewFrame() { 
        return mNewFrameAvailable;
    } 
 
    public synchronized void endCapture() { 
        mIsOpen = false;
        if (mCamera != null) {
            mCamera.release();
            mCamera = null;
            mSurfaceTexture = null;
        } 
    } 
 
    public synchronized boolean isOpen() { 
        return mIsOpen;
    } 
 
    public int getWidth() { 
        return mWidth;
    } 
 
    public int getHeight() { 
        return mHeight;
    } 
 
    public void setCameraFrameListener(CameraFrameListener listener) {
        mListener = listener;
    } 
 
    private void openCamera(int width, int height) {
        // Setup camera 
        mCamera = Camera.open(mCameraId);
        mCamera.setParameters(calcCameraParameters(width, height));
 
        // Create camera surface texture 
        try { 
            mCamera.setPreviewTexture(mSurfaceTexture);
        } catch (IOException e) {
            throw new RuntimeException("Could not bind camera surface texture: " +
                                       e.getMessage() + "!");
        } 
 
        // Connect SurfaceTexture to callback 
        mSurfaceTexture.setOnFrameAvailableListener(onCameraFrameAvailableListener);
    } 
 
    private Camera.Parameters calcCameraParameters(int width, int height) {
        Camera.Parameters params = mCamera.getParameters();
        params.setPreviewSize(mWidth, mHeight);
 
        // Find closest size 
        int closestSize[] = findClosestSize(width, height, params);
        mWidth = closestSize[0];
Connect your IDE to all the code out there  Get Codota for Java