gpt4 book ai didi

java - 在 Android 上拍摄背景照片

转载 作者:太空宇宙 更新时间:2023-11-04 13:02:52 26 4
gpt4 key购买 nike

所以我想使用相机 Intent

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

我想在捕获图片时做一些事情,我的问题是我可以在显示屏上有其他东西时在后台进行捕获而不是显示图片吗?预先感谢您的帮助

最佳答案

这是之前做过的一个项目的 fragment ,希望对您有所帮助:

  // 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)



}
}

关于java - 在 Android 上拍摄背景照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34787122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com