How do I access the camera on Android phones?

前端 未结 4 1708
庸人自扰
庸人自扰 2021-02-13 17:08

I\'ve written a program in Java that takes in an image file and manipulates the image. Now I\'m trying to access the camera so that I can take the photo and give it to the image

4条回答
  •  借酒劲吻你
    2021-02-13 17:36

    There are two methods to take photo for your android application

    1)Using Intent

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    
    fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
    
    // start the image capture Intent
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    

    2) Creating a customized camera activity. For that you need following steps

     * Detect and Access Camera
     * Create a Preview Class
     * Build a Preview Layout 
     * Capture and Save Files
     * Release the Camera
    

    You may also refer the following links:

    http://developer.android.com/guide/topics/media/camera.html http://developer.android.com/reference/android/hardware/Camera.html

提交回复
热议问题