我正在我的应用程序中创建一个自定义相机来拍摄一个返回 null 到我的背部活动的图像......
这是我的自定义相机代码.....
public class CustomCameraActivity extends Activity implements SurfaceHolder.Callback {
public Camera mCamera;
public SurfaceView mSurfaceView;
public SurfaceHolder mSurfaceHolder;
public boolean previewing = false;
public LayoutInflater mLayoutInflater;
public Button btn_Capture;
public byte[] mPictureBytes;
public Intent mIntent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cameraview);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
getWindow().setFormat(PixelFormat.UNKNOWN);
mIntent = getIntent();
mSurfaceView = (SurfaceView) findViewById(R.id.cameraView);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mLayoutInflater = LayoutInflater.from(getBaseContext());
View viewControl = mLayoutInflater
.inflate(R.layout.controlbutton, null);
LayoutParams layoutParamsControl = new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);
btn_Capture = (Button) findViewById(R.id.btn_capture);
btn_Capture.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
mCamera.takePicture(myShutterCallBack, myPictureCallback_RAW, myPictureCallback_JPEG);
mIntent.putExtra("mPictureBytes", mPictureBytes);
Log.d("mPictureBytes", String.valueOf(mPictureBytes));
setResult(007, mIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
ShutterCallback myShutterCallBack = new ShutterCallback() {
@Override
public void onShutter() {
}
};
PictureCallback myPictureCallback_RAW = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
}
};
PictureCallback myPictureCallback_JPEG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
} catch (Exception e) {
e.printStackTrace();
} finally {
mPictureBytes = data;
}
}
};
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
try {
if (previewing) {
mCamera.stopPreview();
previewing = false;
}
if (mCamera != null) {
mCamera.setPreviewDisplay(mSurfaceHolder);
mCamera.startPreview();
previewing = true;
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
previewing = false;
}
}
如果我在 finally 块应用程序中分配数据(字节 []),如果我把它放在 try catch 块中,它会返回 null ......
我想将此图像或字节 [] 发送到我的背部活动.....