バックアクティビティに 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 ブロック applicatio gose ハングで data(byte[]) を割り当てると、それを try catch ブロックに入れると null が返されます......
この Image または byte[] をバック アクティビティに送信したい.....