简体   繁体   English

SD卡中的Android相机存储

[英]Android Camera storage in SD Card

I am making an application in which user clicks a photo from the device camera and then set this image into an image view in next activity. 我正在制作一个应用程序,其中用户单击设备照相机中的照片,然后在下一个活动中将此图像设置为图像视图。

What happens is when I click on the camera button in my first activity the device camera's get opens and then user clciks the capture button and then it gets set in the imageview in next activity. 发生的情况是,当我在第一个活动中单击“相机”按钮时,设备相机的获取打开,然后用户单击“捕获”按钮,然后在下一个活动中将其设置在imageview中。 here is my part of code 这是我的代码部分

   public void loadImagefromGallery(View view) {
    try {
       // photo = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + "/DCIM", photoid + ".jpg");                                                           //image gets stored in DCIM folder in device's inernal memory
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
        imageUri = Uri.fromFile(photo);
        startActivityForResult(intent, TAKE_PICTURE);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

this is my onActivityResult method 这是我的onActivityResult方法

   @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case TAKE_PICTURE:
            if (resultCode == Activity.RESULT_OK) {
                try {
                    Intent intent = new Intent(this,                websters.photobooth.ImageDisplay.class);                          //sending this image to next activity
                    intent.putExtra("picture", photoid + ".jpg");
                    startActivity(intent);
                } catch (Exception e) {
                    Toast.makeText(this, e + "Failed to load", Toast.LENGTH_SHORT)
                            .show();
                    Log.e("Camera", e.toString());
                }
            }}
}

Now what I want is when Take picture button is clicked,then Camera gets opened and then after 3 secs image automatically gets clicked without any user interaction. 现在我想要的是单击“拍照”按钮时,然后打开“相机”,然后在3秒钟后自动单击图像,而无需任何用户交互。 Also for now all the images are stored in the Internal storage I want is to store them in the memory Card in some particular folder named "photobooth". 同样,现在所有图像都存储在内部存储器中,我想将它们存储在存储卡中名为“ photobooth”的某个特定文件夹中。 Help me out guys. 帮帮我。

if you want to capture image without user intraction then please refer this sample code which one is provided by google https://github.com/googlesamples/android-Camera2Basic and simple use CountDownTimer class here may have provide some code for your refrence how you can captcher picture. 如果您想在不吸引用户的情况下捕获图像,请参考此示例代码,该示例代码由google https://github.com/googlesamples/android-Camera2Basic提供,此处简单易用CountDownTimer类可能为您提供了一些代码参考可以捕捉照片。

    private void openCamera(int width, int height) {
        if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            requestCameraPermission();
            return;
        }
        setUpCameraOutputs(width, height);
        configureTransform(width, height);
        Activity activity = getActivity();
        CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
        try {
            if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
                throw new RuntimeException("Time out waiting to lock camera opening.");
            }
            manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            throw new RuntimeException("Interrupted while trying to lock camera opening.", e);
        }
    }


    private void takePicture() {
        lockFocus();
    }

    /**
     * Lock the focus as the first step for a still image capture.
     */
    private void lockFocus() {
        try {
            // This is how to tell the camera to lock focus.
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_START);
            // Tell #mCaptureCallback to wait for the lock.
            mState = STATE_WAITING_LOCK;
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                    mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }

    new CountDownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         openCamera(your_required_width, your_required_height)
     }

     public void onFinish() {
         takePicture()
     }
  }.start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM