Search This Blog

Monday 21 July 2014

Develop the camera using eclipse


Develop the camera  using eclipse

Basics:

here you are get your first rear facing camera. with help of the eclipse android developer. 

In this post you can know how to control camera hardware directly using the framework APIs.

Most Android devices have at least one camera. Some devices have a front and a back facing camera.Using the camera on the Android device can be done via the integration of existing camera application. In this case you would start the existing Camera application via an intent and use the return data of the application to access the result.Alternatively you can also directly integrate the camera into your application via the Camera API.


Using existing android camera application in our application:


You will use Media Store.ACTION_IMAGE_CAPTURE to launch an existing camera application installed on your phone. Its syntax is given below

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

Open the camera object:

In the first step in the process of directly controlling camera first of all getting an instance of the  Camera object.As Android's own camera application does,the recommended way to access the camera is to open  Camera on a separate thread that's lunched from  onCreate().

This approach is good idea since it can take a while and might bog down the UI thread.In a more basic implementation opening the camera can be deferred to the onResume() method to facilities code reuse and the keep the flow of control simple. 

Now calling the Camera.open() method and it throws an exception if the camera already in use by another application ,so we wrap it in a try block.



private boolean safeCameraOpen(int id) {
    boolean qOpened = false;
  
    try {
        releaseCameraAndPreview();
        mCamera = Camera.open(id);
        qOpened = (mCamera != null);
    } catch (Exception e) {
        Log.e(getString(R.string.app_name), "failed to open Camera");
        e.printStackTrace();
    }

    return qOpened;    
}

private void releaseCameraAndPreview() {
    mPreview.setCamera(null);
    if (mCamera != null) {
        mCamera.release();
        mCamera = null;
    }
}
Since API level 9, The camera framework supports multiple cameras. If you use the legacy API and call open()with out an argument you get a first rear facing camera.   

No comments:

Post a Comment