在建设自己的摄像头的Andr​​oid问题自己的、摄像头、问题、Andr

2023-09-06 06:46:28 作者:遇见你时风好甜

我曾尝试使用意图,像这样在启动相机的android:

 意图摄像头=新的意图(MediaStore.ACTION_IM​​AGE_CAPTURE)
 

但自从我保存的图片进行了定向水平,并能找到一种方法来解决,我试图用这个神奇的一块code建设自己的摄像头的Andr​​oid:

 公共类EditPhoto扩展活动实现SurfaceHolder.Callback,
        OnClickListener {
    静态最终诠释FOTO_MODE = 0;
    私有静态最后字符串变量=CameraTest;
    相机mCamera;
    布尔米previewRunning = FALSE;
    民营背景mContext =这一点;

    公共无效的onCreate(包冰柱){
        super.onCreate(冰柱);

        Log.e(TAG的onCreate);

        捆绑额外= getIntent()getExtras()。

        。getWindow()和setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        的setContentView(R.layout.editphoto);
        mSurfaceView =(SurfaceView)findViewById(R.id.surface_camera);
        mSurfaceView.setOnClickListener(本);
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(本);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @覆盖
    保护无效onRestoreInstanceState(包savedInstanceState){
        super.onRestoreInstanceState(savedInstanceState);
    }

    Camera.PictureCallback mPictureCallback =新Camera.PictureCallback(){
        公共无效onPictureTaken(byte []的为imageData,摄像机C){

            如果(为imageData!= NULL){

                意图mIntent =新意图();

                StoreByteImage(mContext,为imageData,50,
                        ImageName);
                mCamera.start preVIEW();

                的setResult(FOTO_MODE,mIntent);
                完();

            }
        }
    };

    保护无效onResume(){
        Log.e(TAG,onResume);
        super.onResume();
    }

    保护无效的onSaveInstanceState(包outState){
        super.onSaveInstanceState(outState);
    }

    保护无效的onStop(){
        Log.e(TAG的onStop);
        super.onStop();
    }

    公共无效surfaceCreated(SurfaceHolder持有者){
        Log.e(TAG,surfaceCreated);
        mCamera = Camera.open();

    }

    公共无效surfaceChanged(SurfaceHolder持有人,INT格式,INT W,INT高){
        Log.e(TAG,surfaceChanged);

        // XXX停止preVIEW()会崩溃,如果preVIEW没有运行
        如果(M previewRunning){
            mCamera.stop preVIEW();
        }

        Camera.Parameters p值= mCamera.getParameters();
        P.SET previewSize(W,H);
        mCamera.setParameters(对);
        尝试 {
            mCamera.set previewDisplay(保持器);
        }赶上(IOException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
        mCamera.start preVIEW();
        米previewRunning = TRUE;
    }

    公共无效surfaceDestroyed(SurfaceHolder持有者){
        Log.e(TAG,surfaceDestroyed);
        mCamera.stop preVIEW();
        米previewRunning = FALSE;
        mCamera.release();
    }

    私人SurfaceView mSurfaceView;
    私人SurfaceHolder mSurfaceHolder;

    公共无效的onClick(查看为arg0){

        mCamera.takePicture(NULL,mPictureCallback,mPictureCallback);

    }

    公共静态布尔StoreByteImage(上下文mContext,byte []的为imageData,
            INT质量,串expName){

        文件sdImageMainDirectory =新的文件(/ SD卡);
        FileOutputStream中的FileOutputStream = NULL;
        字符串nameFile;
        尝试 {

            BitmapFactory.Options选项=新BitmapFactory.Options();
            options.inSampleSize = 5;
            位图MYIMAGE = BitmapFactory.de codeByteArray(为imageData,0,
                    imageData.length,期权);
            的FileOutputStream =新的FileOutputStream(
                    sdImageMainDirectory.toString()+/ image.jpg的);
            的BufferedOutputStream BOS =新的BufferedOutputStream(
                    FileOutputStream中);

            myImage.com preSS(比较pressFormat.JPEG,质量,BOS);

            bos.flush();
            bos.close();

            }赶上(FileNotFoundException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
            }赶上(IOException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
            }

            返回true;
             }

}
 

我有一个摄像头的权限在manifest文件,但我唯一看到的是一个白色的屏幕和一个logcat的,看起来像这样:

 了java.lang.RuntimeException:无法连接到摄像机服务
 在android.hardware.Camera.native_setup(本机方法)
 在android.hardware.Camera< INIT>(Camera.java:258)
 在android.hardware.Camera.open(Camera.java:235)
  在com.SplashScreen.EditPhoto.surfaceCreated(EditPhoto.java:325)
在android.view.SurfaceView.updateWindow(SurfaceView.java:543)
 在android.view.SurfaceView.dispatchDraw(SurfaceView.java:348)
在android.view.ViewGroup.drawChild(ViewGroup.java:1644)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
在android.view.ViewGroup.drawChild(ViewGroup.java:1644)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
在android.view.ViewGroup.drawChild(ViewGroup.java:1644)
在android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
在android.view.View.draw(View.java:6883)
 在android.widget.FrameLayout.draw(FrameLayout.java:357)
在com.android.internal.policy.impl.PhoneWindow $ DecorView.draw(PhoneWindow.java:1862)
在android.view.ViewRoot.draw(ViewRoot.java:1522)
在android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
在android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:123)
在android.app.ActivityThread.main(ActivityThread.java:3647)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:507)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
在dalvik.system.NativeStart.main(本机方法)
力整理活动com.SplashScreen / .EditPhoto
 

所以,请你善待,告诉我什么,我做错了什么?谢谢!

编辑:清单文件 -

 <使用特征的android:NAME =android.hardware.camera/>
    <使用-权限的Andr​​oid:名称=android.permission.CAMERA/>
<使用特征的android:NAME =android.hardware.camera.autofocus/>
 

XML文件:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>

< SurfaceView
 机器人:ID =@ + ID / surface_camera
   机器人:layout_width =FILL_PARENT
   机器人:layout_height =FILL_PARENT
   />


< / LinearLayout中>
 

解决方案

旅游活动 EditPhoto.java 在我的API级别工作完美7 AVD,

 包xy格式;

进口java.io.BufferedOutputStream;
进口的java.io.File;
进口java.io.FileNotFoundException;
进口java.io.FileOutputStream中;
进口java.io.IOException异常;

进口android.app.Activity;
进口android.content.Context;
进口android.content.Intent;
进口android.graphics.Bitmap;
进口android.graphics.Bitmap.Com pressFormat;
进口android.graphics.BitmapFactory;
进口android.hardware.Camera;
进口android.graphics.PixelFormat;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.SurfaceHolder;
进口android.view.SurfaceView;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.view.Window;
进口android.view.WindowManager;

公共类EditPhoto扩展活动实现SurfaceHolder.Callback,OnClickListener {
    静态最终诠释FOTO_MODE = 0;
    私有静态最后字符串变量=CameraTest;
    相机mCamera;
    布尔米previewRunning = FALSE;
    民营背景mContext =这一点;

    公共无效的onCreate(包冰柱){
        super.onCreate(冰柱);

        Log.e(TAG的onCreate);

        捆绑额外= getIntent()getExtras()。

        。getWindow()和setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow()setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN)。
        的setContentView(R.layout.main);
        mSurfaceView =(SurfaceView)findViewById(R.id.surface_camera);
        mSurfaceView.setOnClickListener(本);
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(本);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @覆盖
    保护无效onRestoreInstanceState(包savedInstanceState){
        super.onRestoreInstanceState(savedInstanceState);
    }

    Camera.PictureCallback mPictureCallback =新Camera.PictureCallback(){
        公共无效onPictureTaken(byte []的为imageData,摄像机C){

            如果(为imageData!= NULL){

                意图mIntent =新意图();

                StoreByteImage(mContext,为imageData,50,ImageName);
                mCamera.start preVIEW();

                叠B =新包();
                b.putByteArray(为imageData,为imageData);
                意图I =新的意图(mContext,ImageDisplayActivity.class);
                i.putExtras(B);
                startActivity(ⅰ);

                的setResult(FOTO_MODE,mIntent);
                完();

            }
        }
    };

    保护无效onResume(){
        Log.e(TAG,onResume);
        super.onResume();
    }

    保护无效的onSaveInstanceState(包outState){
        super.onSaveInstanceState(outState);
    }

    保护无效的onStop(){
        Log.e(TAG的onStop);
        super.onStop();
    }

    公共无效surfaceCreated(SurfaceHolder持有者){
        Log.e(TAG,surfaceCreated);
        mCamera = Camera.open();

    }

    公共无效surfaceChanged(SurfaceHolder持有人,INT格式,INT W,INT高){
        Log.e(TAG,surfaceChanged);

        // XXX停止preVIEW()会崩溃,如果preVIEW没有运行
        如果(M previewRunning){
            mCamera.stop preVIEW();
        }

        Camera.Parameters p值= mCamera.getParameters();
        P.SET previewSize(W,H);
        mCamera.setParameters(对);
        尝试 {
            mCamera.set previewDisplay(保持器);
        }赶上(IOException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
        mCamera.start preVIEW();
        米previewRunning = TRUE;
    }

    公共无效surfaceDestroyed(SurfaceHolder持有者){
        Log.e(TAG,surfaceDestroyed);
        mCamera.stop preVIEW();
        米previewRunning = FALSE;
        mCamera.release();
    }

    私人SurfaceView mSurfaceView;
    私人SurfaceHolder mSurfaceHolder;

    公共无效的onClick(查看为arg0){

        mCamera.takePicture(NULL,mPictureCallback,mPictureCallback);

    }

    公共静态布尔StoreByteImage(上下文mContext,byte []的为imageData,诠释品质,串expName){

        文件sdImageMainDirectory =新的文件(/ SD卡);
        FileOutputStream中的FileOutputStream = NULL;
        字符串nameFile;
        尝试 {

            BitmapFactory.Options选项=新BitmapFactory.Options();
            options.inSampleSize = 5;
            位图MYIMAGE = BitmapFactory.de codeByteArray(为imageData,0,imageData.length,期权);
            的FileOutputStream =新的FileOutputStream(sdImageMainDirectory.toString()+/ image.jpg文件);
            的BufferedOutputStream BOS =新的BufferedOutputStream(FileOutputStream中);

            myImage.com preSS(比较pressFormat.JPEG,质量,BOS);

            bos.flush();
            bos.close();

        }赶上(FileNotFoundException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }赶上(IOException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }

        返回true;
    }

}
 

我张贴我的布局和清单在这里...

布局editphoto.xml

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
< SurfaceView
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
   机器人:ID =@ + ID / surface_camera
    />
< / LinearLayout中>
 

和清单文件...

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
      包=xy格式
      安卓版code =1
      机器人:VERSIONNAME =1.0>
    <应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
        <活动机器人:名称=。EditPhoto
                  机器人:标签=@字符串/ APP_NAME>
            <意向滤光器>
                <作用机器人:名称=android.intent.action.MAIN/>
                <类机器人:名称=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;

    <活动机器人:名称=ImageDisplayActivity>< /活性GT;
< /用途>


<使用-权限的Andr​​oid:名称=android.permission.CAMERA>< /使用-许可>

< /舱单>
 

新活动,以显示图像 ImageDisplayActivity.java (图片将显示,当你会点击表面观)......

 包xy格式;

进口android.app.Activity;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.os.Bundle;
进口android.widget.ImageView;

公共类ImageDisplayActivity延伸活动{

    公共无效的onCreate(包冰柱){
        super.onCreate(冰柱);
        捆绑额外= getIntent()getExtras()。
        的setContentView(R.layout.anotherlayout);

        BitmapFactory.Options选项=新BitmapFactory.Options();
        options.inSampleSize = 5;
        byte []的为imageData = extras.getByteArray(为imageData);
        位图MYIMAGE = BitmapFactory.de codeByteArray(为imageData,0,imageData.length,期权);


        ImageView的ImageView的=(ImageView的)findViewById(R.id.myPic);
        imageView.setImageBitmap(MYIMAGE);
    }
}
 

和它的布局 otherlayout.xml ...

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
< ImageView的
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:layout_gravity =中心
   机器人:ID =@ + ID / myPic
    />
< / LinearLayout中>
 

I have tried starting the camera in android using an intent, something like this:

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE) 

but since my saved pictures were orientated horizontally and could find a way to fix that I tried building my own camera in android using this marvelous piece of code:

public class EditPhoto extends Activity implements SurfaceHolder.Callback,
        OnClickListener {
    static final int FOTO_MODE = 0;
    private static final String TAG = "CameraTest";
    Camera mCamera;
    boolean mPreviewRunning = false;
    private Context mContext = this;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        Log.e(TAG, "onCreate");

        Bundle extras = getIntent().getExtras();

        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.editphoto);
        mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
        mSurfaceView.setOnClickListener(this);
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }

    Camera.PictureCallback mPictureCallback = new Camera.PictureCallback(){
        public void onPictureTaken(byte[] imageData, Camera c) {

            if (imageData != null) {

                Intent mIntent = new Intent();

                StoreByteImage(mContext, imageData, 50,
                        "ImageName");
                mCamera.startPreview();

                setResult(FOTO_MODE, mIntent);
                finish();

            }
        }
    };

    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();

    }

    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;

    public void onClick(View arg0) {

        mCamera.takePicture(null, mPictureCallback, mPictureCallback);

    }

    public static boolean StoreByteImage(Context mContext, byte[] imageData,
            int quality, String expName) {

        File sdImageMainDirectory = new File("/sdcard");
        FileOutputStream fileOutputStream = null;
        String nameFile;
        try {

            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inSampleSize = 5;
            Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
                    imageData.length,options);
            fileOutputStream = new FileOutputStream(
                    sdImageMainDirectory.toString() +"/image.jpg");
            BufferedOutputStream bos = new BufferedOutputStream(
                    fileOutputStream);

            myImage.compress(CompressFormat.JPEG, quality, bos);

            bos.flush();
            bos.close();

            } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            }

            return true;
             }

}

I have permissions for camera in the manifest file but the only thing that I see is a white screen and a logcat that looks like this:

java.lang.RuntimeException: Fail to connect to camera service
 at android.hardware.Camera.native_setup(Native Method)
 at android.hardware.Camera.<init>(Camera.java:258)
 at android.hardware.Camera.open(Camera.java:235)
  at com.SplashScreen.EditPhoto.surfaceCreated(EditPhoto.java:325)
at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
 at android.view.SurfaceView.dispatchDraw(SurfaceView.java:348)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:6883)
 at android.widget.FrameLayout.draw(FrameLayout.java:357)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
at android.view.ViewRoot.draw(ViewRoot.java:1522)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.SplashScreen/.EditPhoto

So would you please be kind and tell me what I'm doing wrong?Thank you!

EDIT:Manifest file-

<uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />

XML file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:orientation="vertical">

<SurfaceView
 android:id="@+id/surface_camera" 
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   />


</LinearLayout>

解决方案

Tour activity EditPhoto.java working perfectly in my API level 7 AVD,

package x.y;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;

public class EditPhoto extends Activity implements SurfaceHolder.Callback, OnClickListener {
    static final int FOTO_MODE = 0;
    private static final String TAG = "CameraTest";
    Camera mCamera;
    boolean mPreviewRunning = false;
    private Context mContext = this;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        Log.e(TAG, "onCreate");

        Bundle extras = getIntent().getExtras();

        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
        mSurfaceView.setOnClickListener(this);
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }

    Camera.PictureCallback mPictureCallback = new Camera.PictureCallback(){
        public void onPictureTaken(byte[] imageData, Camera c) {

            if (imageData != null) {

                Intent mIntent = new Intent();

                StoreByteImage(mContext, imageData, 50, "ImageName");
                mCamera.startPreview();

                Bundle b = new Bundle();
                b.putByteArray("imageData", imageData);
                Intent i = new Intent(mContext, ImageDisplayActivity.class);
                i.putExtras(b);
                startActivity(i);

                setResult(FOTO_MODE, mIntent);
                finish();

            }
        }
    };

    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();

    }

    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;

    public void onClick(View arg0) {

        mCamera.takePicture(null, mPictureCallback, mPictureCallback);

    }

    public static boolean StoreByteImage(Context mContext, byte[] imageData, int quality, String expName) {

        File sdImageMainDirectory = new File("/sdcard");
        FileOutputStream fileOutputStream = null;
        String nameFile;
        try {

            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inSampleSize = 5;
            Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length,options);
            fileOutputStream = new FileOutputStream(sdImageMainDirectory.toString() +"/image.jpg");
            BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);

            myImage.compress(CompressFormat.JPEG, quality, bos);

            bos.flush();
            bos.close();

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return true;
    }

}

i am posting my Layout and Manifest here ...

Layout editphoto.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<SurfaceView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
   android:id="@+id/surface_camera"
    />
</LinearLayout>

and Manifest file ...

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="x.y"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".EditPhoto"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    <activity android:name="ImageDisplayActivity"></activity>
</application>


<uses-permission android:name="android.permission.CAMERA"></uses-permission>

</manifest> 

New Activity to display image ImageDisplayActivity.java (Image will be displayed when you will click on surface view)....

package x.y;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class ImageDisplayActivity extends Activity {

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        Bundle extras = getIntent().getExtras();
        setContentView(R.layout.anotherlayout);

        BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 5;
        byte[] imageData = extras.getByteArray("imageData");
        Bitmap myImage = BitmapFactory.decodeByteArray(imageData , 0, imageData.length,options);


        ImageView imageView = (ImageView) findViewById(R.id.myPic);
        imageView.setImageBitmap(myImage);
    }   
}

and it's layout otherlayout.xml ...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ImageView  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center"
   android:id="@+id/myPic"
    />
</LinearLayout>