开发者

How big is interval between taking pictures in Android phone?

I'm wondering how fast I can take pictures one after another withoud surprises from the phone (like fx: 'force close;)

Does any of you know that time?

I know that 500 milisec is safe time. When i experiment with 100, 200, 300 mi开发者_运维问答lisec there is error but who knows, maybe i do sth wrong.


This absolutely depends on what you define as "take a picture" - as Nathan mentioned, when recording video (basically a series of scaled-down, compressed pictures) you can "take" a picture every 30ms. But if you define "taking a picture" as copying a 5MP jpeg picture to the SD card, this will probably take longer.

You have to explicitly describe what you mean when you say "just make a loop(to take 1000 pics)," especially when you are complaining of errors.

Assuming you extend the Camera.PictureCallback interface, a lot of processing goes on behind the scenes before you get passed the picture (like jpeg compression, I believe). Have you tried throwing an event inside your implementation of onPictureTaken to take another picture? This might be a safe way of doing and testing what you want. Otherwise if you fire off a ton of "take a picture" events, some kind of heap overflow might happen, I don't know.

Edit: Roughly speaking, this is what I meant:

public void onPictureTaken(
        final byte [] data, final android.hardware.Camera camera) {
    saveDataToFile("/DCIM/tempjpeg.jpg", data);
    camera.takePicture(null, null, this);
}

Call takePicture as soon as you can - right in the callback! DO NOT USE THIS without modification, since this will loop forever. I tried this, and it works for a couple pics, then is just stops responding. If you stop it after two pics, it seems to take under a second on a Nexus One. Hopes that helps.


That would really depend on the device you are using actually apart from the software problems. I would just run the tests on the phone by automatically taking some fixed number of pictures (like 1000), timing them and finding average time and standard deviation from that. Doing that on a couple of devices and the emulator would definitely give you a sense of how long it actually takes.


Well the Motorola droid can take 30fps video, so if you need really fast images, maybe you could use MediaRecorder


boolean isTakingPicture = false;


public void onclick2takepic(View view) {
      try {
        if(!isTakingPicture) {
            mCamera.takePicture(null, null, mPicture);
            isTakingPicture = true;
        }else{
            isTakingPicture=false;
        }
    }catch(Exception e){
        Toast.makeText(this,"cannot take picture: "+e.getMessage(),Toast.LENGTH_SHORT).show();
    }
}


    private Camera.PictureCallback mPicture = new Camera.PictureCallback(){
    @Override
public void onPictureTaken(byte[] data, Camera camera){
        File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
        if(pictureFile==null){
            Toast.makeText(getApplicationContext(),"error creating media file, check permissions",Toast.LENGTH_LONG).show();
            return;
        }
        try{
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();
        }catch(FileNotFoundException e){
            //Toast.makeText(this,"file not found: "+e.getMessage()).show();
        }catch(IOException e){
            //Toast.makeText(getApplicationContext(),"error accessing file: "+e.getMessage()).show();
        }
        //isTakingPicture = false;
        mCamera.startPreview();
        if(isTakingPicture) {
            mCamera.takePicture(null, null, mPicture);
        }
    }
};

In this code there is a recursion that restarts preview and takes picture again as long as isTakingPicture=true; turning preview on and off is time consuming so i cant get more then a couple of pictures per second on my old phones. would like to be able to do this not through takePicture as it cant shoot without preview but with mediaRecorder but have no idea how yet

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜