通过Intent拍摄多张照片

时间:2014-08-19 11:09:56

标签: java android android-intent camera

我想通过Intent拍摄多张照片。我知道如何制作一张只拍摄一张图片的意图,但是如果我想拍摄一张图片,该怎么办? 10张照片?

static final int REQUEST_IMAGE_CAPTURE = 1;

private void dispatchTakePictureIntent() {
  Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
      startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
  }
}

琐碎的解决方案是在结果之后制定另一个意图,但我认为必须有更好的解决方案,不是吗?

2 个答案:

答案 0 :(得分:1)

你必须通过使用一些技巧做一些事情,stackoverflow上提出的问题之一将帮助你,see this link 第二次检查this link 这两个链接肯定会对你有所帮助。 第二个链接推荐此代码

Intent intent = new Intent(
    MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
this.startActivity(intent);

答案 1 :(得分:0)

就我而言,我不得不使用MediaStore.ACTION_IMAGE_CAPTURE来禁止从手机库中选择图像。

为了在拍摄多张照片时达到“类似”的效果,我直接从onActivityResult开始下一个相机意图,同时在后台处理最近拍摄的照片。

代码如下:

...
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode != REQUEST_IMAGE_CAPTURE) {
            return
        }
        if (resultCode == Activity.RESULT_CANCELED) {
            Timber.d("Taking image was cancelled")
            return
        }
        if (resultCode == Activity.RESULT_OK) {
            lastTakenPhotoData?.let {
                handlePhotoTaken(it)
                startCameraIntent()
            }
        }
    }
...

    private fun handlePhotoTaken(...) {
        disposable.add(
            Single.fromCallable { compressPhotoTaken(data) }
                    .subscribeOn(Schedulers.computation())
                    .observeOn(AndroidSchedulers.mainThread()).subscribe { _ ->
                        //update UI with processed photo
                    }
        )
    }
...
    private fun compressTakenPhoto(...) {
        //rotate, compress, save taken photo to the local file if needed
        //this part was taking quite a lot of time, so it is better to do it in background
    }