views:

53

answers:

2

I would like to do something like this.

If the user presses "Pictures" than i can choose either to pick a picture from "Picture folder" or take a new picture,

How can I do this and how can I use the cam? I have problems useing the cam, Does the cam work in the simulator?

A: 

I'am getting error, do i need a webcam on my computure?

This is the code:

public class PreviewDemo extends Activity {
private SurfaceView preview = null;
private SurfaceHolder previewHolder= null;
private Camera camera = null;

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.camera);

    preview = (SurfaceView) findViewById(R.id.preview);
    previewHolder = preview.getHolder();
    previewHolder.addCallback(surfaceCallback);
    previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {

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

    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        camera = Camera.open();

        try{
            camera.setPreviewDisplay(previewHolder);
        }
        catch(Throwable t){
            Log.e("PreviewDemo-surfaceCallback",
                    "Exception in setPreviewDisplay()", t);
            Toast.makeText(PreviewDemo.this, t.getMessage(), Toast.LENGTH_LONG).show();
        }
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        Camera.Parameters parameters = camera.getParameters();
        parameters.setPreviewSize(width, height);
        camera.startPreview();
    }
};

}

Troj
A: 

You can try to use the camera on the simulator, it's working well :)

Don't forget to give you the security rights into the Manifest.

Don't forget also than every android devices doesn't have one !

http://developer.android.com/reference/android/hardware/Camera.html

ykatchou