0
我有代码拍摄的图片,但它得到PictureCallback()
后,它继续在代码方面徘徊,我最终在我有我的字节之前执行其他代码阵列。有什么办法可以制止这个吗?它只需要几毫秒,我不认为我会介意停止UI线程。Android的PictureCallback需要先执行然后继续到其他代码
private static byte[] patronImage;
.
.
.
takePatronPicture();
//I want to do something with patronImage here, but the next line
//gets executed almost immediately while getJpegCallback is still
//doing its thing.
code that does something with patronImage;
.
.
.
public void takePatronPicture(){
if (camera != null) {
try {
SurfaceView surfaceView = (SurfaceView)getView().findViewById(R.id.surfaceView1);
camera.setPreviewDisplay(surfaceView.getHolder());
camera.startPreview();
camera.takePicture(null, null, getJpegCallback);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
final PictureCallback getJpegCallback = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
patronImage = data;
camera.release();
camera = null;
} catch (final Exception e) {
e.printStackTrace();
}
}
};
谢谢。有时候我看不到树木的阿甘。 – Clutch