i dunno how this camera api works... but if u jus need to take a pic u can
use the in-built camera application...

On Mon, Jun 1, 2009 at 7:47 PM, jaimin <jaiminmeht...@gmail.com> wrote:

>
> hi i am new to android .
> i want to devlope for camera api
> but i have some problem in my code
> when i tried to capture image it gives me force close errors
>
>
> package indiaNIC.android.cameratest;
>
> import java.io.IOException;
>
> import android.app.Activity;
> import android.content.Intent;
> import android.graphics.PixelFormat;
> import android.hardware.Camera;
> import android.net.Uri;
> import android.os.Bundle;
> import android.util.Log;
> import android.view.KeyEvent;
> import android.view.MenuItem;
> import android.view.SurfaceHolder;
> import android.view.SurfaceView;
>
> public class cameratest extends Activity implements
> SurfaceHolder.Callback
> {
>    private static final String TAG = "CameraApiTest";
>    Camera mCamera;
>    boolean mPreviewRunning = false;
>
>    public void onCreate(Bundle icicle)
>    {
>        super.onCreate(icicle);
>
>        Log.e(TAG, "onCreate");
>
>        getWindow().setFormat(PixelFormat.TRANSLUCENT);
>
>        setContentView(R.layout.main);
>        mSurfaceView = (SurfaceView)findViewById(R.id.surface);
>
>        mSurfaceHolder = mSurfaceView.getHolder();
>        mSurfaceHolder.addCallback(this);
>        mSurfaceHolder.setType
> (SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
>    }
>
>    public boolean onCreateOptionsMenu(android.view.Menu menu) {
>        MenuItem item = menu.add(0, 0, 0, "goto gallery");
>        item.setOnMenuItemClickListener(new
> MenuItem.OnMenuItemClickListener() {
>            public boolean onMenuItemClick(MenuItem item) {
>                Uri target = Uri.parse("content://media/external/
> images/media");
>                Intent intent = new Intent(Intent.ACTION_VIEW,
> target);
>                startActivity(intent);
>                return true;
>            }
>        });
>        return true;
>    }
>
>    @Override
>    protected void onRestoreInstanceState(Bundle savedInstanceState)
>    {
>        super.onRestoreInstanceState(savedInstanceState);
>    }
>
>    Camera.PictureCallback mPictureCallback = new
> Camera.PictureCallback() {
>        public void onPictureTaken(byte[] data, Camera c) {
>            Log.e(TAG, "PICTURE CALLBACK: data.length = " +
> data.length);
>            mCamera.startPreview();
>        }
>    };
>
>    public boolean onKeyDown(int keyCode, KeyEvent event)
>    {
>        if (keyCode == KeyEvent.KEYCODE_BACK) {
>            return super.onKeyDown(keyCode, event);
>        }
>
>        if (keyCode == KeyEvent.KEYCODE_SPACE) {
>            mCamera.takePicture(null, mPictureCallback,
> mPictureCallback);
>            return true;
>        }
>
>        return false;
>    }
>
>    protected void onResume()
>    {
>        Log.e(TAG, "onResume");
>        super.onResume();
>    }
>
>    protected void onSaveInstanceState(Bundle outState)
>    {
>        super.onSaveInstanceState(outState);
>    }
>
>    protected void onStop()
>    {
>        Log.e(TAG, "onStop");
>        super.onStop();
>    }
>
>    public void surfaceCreated(SurfaceHolder holder)
>    {
>        Log.e(TAG, "surfaceCreated");
>        mCamera = Camera.open();
>        //mCamera.startPreview();
>    }
>
>    public void surfaceChanged(SurfaceHolder holder, int format, int
> w, int h)
>    {
>        Log.e(TAG, "surfaceChanged");
>
>        // XXX stopPreview() will crash if preview is not running
>        if (mPreviewRunning) {
>            mCamera.stopPreview();
>        }
>
>        Camera.Parameters p = mCamera.getParameters();
>        p.setPreviewSize(w, h);
>        mCamera.setParameters(p);
>        try {
>                        mCamera.setPreviewDisplay(holder);
>                }
>        catch (IOException e)
>                {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                }
>        mCamera.startPreview();
>        mPreviewRunning = true;
>
>    }
>
>    public void surfaceDestroyed(SurfaceHolder holder)
>    {
>        Log.e(TAG, "surfaceDestroyed");
>        mCamera.stopPreview();
>        mPreviewRunning = false;
>        mCamera.release();
>    }
>
>    private SurfaceView mSurfaceView;
>    private SurfaceHolder mSurfaceHolder;
> }
>
> package indiaNIC.android.cameratest;
>
> import java.io.OutputStream;
>
> import android.graphics.Camera;
> import android.hardware.Camera.PictureCallback;
> import android.util.Log;
>
> public class ImageCaptureCallback implements PictureCallback  {
>
>    private OutputStream filoutputStream;
>    public ImageCaptureCallback(OutputStream filoutputStream) {
>    this.filoutputStream = filoutputStream;
>    }
>
>    public void onPictureTaken(byte[] data, Camera camera) {
>    try {
>   Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + "
> length = " + data.length);
>   filoutputStream.write(data);
>   filoutputStream.flush();
>   filoutputStream.close();
>   } catch(Exception ex) {
>   ex.printStackTrace();
>   }
>   }
>
>        @Override
>        public void onPictureTaken(byte[] arg0, android.hardware.Camera
> arg1)
> {
>                // TODO Auto-generated method stub
>
>        }
>   }
>
>
>
> this 2 java class is my code
> plz help me on this its urgent
>
> >
>


-- 
Regards,
Sujay
W. C. Fields <http://www.brainyquote.com/quotes/authors/w/w_c_fields.html>
- "I am free of all prejudices. I hate every one equally."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to