Androidカメラで4枚の写真を撮っています。各写真の後、カメラですぐにプレビューしてから、別のショットを撮ります。util 私は 4 つを得ました。しかし、アプリケーションを実行すると、最初の写真が撮られ、その後 4 つのカメラの音が聞こえました。他の写真が表示されていると思いますが、表面ビューには表示されていません。どうすればこれを修正できますか?
これが私のコードです。
public class TakePhoto extends Activity implements SurfaceHolder.Callback, OnClickListener{
Camera camera;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean previewing = false;
LayoutInflater controlInflater = null;
TextView textView1 ;
/** Called when the activity is first created. */
ImageView takepicture;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.camerapreview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
controlInflater = LayoutInflater.from(getBaseContext());
View viewControl = controlInflater.inflate(R.layout.control, null);
LayoutParams layoutParamsControl
= new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
this.addContentView(viewControl, layoutParamsControl);
takepicture = (ImageView)findViewById(R.id.takepicture);
takepicture.setOnClickListener(this);
textView1 = (TextView)findViewById(R.id.textView1);
textView1.setText("");
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
if(previewing){
camera.stopPreview();
previewing = false;
}
if (camera != null){
try {
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
previewing = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera = Camera.open(CameraInfo.CAMERA_FACING_FRONT);
camera.setDisplayOrientation(90);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
camera = null;
previewing = false;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.takepicture:
new CountDownTimer(4000, 1000) {
public void onTick(long millisUntilFinished) {
textView1.setText(" " + millisUntilFinished / 1000);
}
public void onFinish() {
textView1.setText("");
//camera.takePicture(myShutterCallback,
//myPictureCallback_RAW, myPictureCallback_JPG);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
camera.startPreview();
camera.takePicture(myShutterCallback, myPictureCallback_JPG, myPictureCallback_JPG);
}
public void onFinish() {
textView1.setText("");
}
}.start();
}
}.start();
break;
}
}
ShutterCallback myShutterCallback = new ShutterCallback(){
@Override
public void onShutter() {
// TODO Auto-generated method stub
}
};
PictureCallback myPictureCallback_RAW = new PictureCallback(){
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub
}
};
PictureCallback myPictureCallback_JPG = new PictureCallback(){
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// TODO Auto-generated method stub
Bitmap bitmapPicture
= BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
}
};
private class CaptureThread extends Thread {
@Override
public void run() {
int count = 0;
while(count < 4) {
camera.takePicture(myShutterCallback, myPictureCallback_JPG, myPictureCallback_JPG);
count++;
try {
Thread.sleep(3000);
} catch (InterruptedException exception) {
exception.printStackTrace();
}
}
}
}
}
}