在Android上拍摄背景图片

时间:2016-01-14 10:26:08

标签: java android camera

所以我想使用相机意图

Intent intent =new Intent("android.media.action.IMAGE_CAPTURE");

我希望在拍摄照片时做点什么,而我的问题是我可以在背景中进行捕捉,而在显示屏上是另外的东西而不是显示照片吗?在此先感谢您的帮助

1 个答案:

答案 0 :(得分:0)

这是以前做过的项目的片段,我希望它会对你有所帮助:

  // Open the camera and take a picture
public void openCamera() {
    Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getIntent.setType("image/*");
    startActivityForResult(getIntent, SEND_MESSAGE_IMG_REQUEST_IMAGE_PICK);
}

// handle the result from camera
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == SEND_MESSAGE_IMG_REQUEST_IMAGE_PICK && resultCode == RESULT_OK) {

        Uri selectedImage = data.getData();
        String[] filePathColumn = {MediaStore.Images.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String filePath = cursor.getString(columnIndex);
        cursor.close();

        // do a background task to handle the captured image (upload it to a server or something like that)



    }
}