gpt4 book ai didi

java - 获取我的 Activity 结果的空数据

转载 作者:行者123 更新时间:2023-12-01 13:10:49 25 4
gpt4 key购买 nike

我有这段代码,我想拍照,然后 onactivityresult 从 Intent 中获取数据,并将其转换为位图以显示 Activity 的一些预览,但数据为空,我不知道为什么。

cameraButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);


}
});

然后是 Activity 结果:

protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);



switch (requestCode) {
case CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE:
if (resultCode == RESULT_OK) {

data = imageReturnedIntent.getData();
InputStream stream;



try {
stream = super.getContentResolver().openInputStream(data);

bitmap = BitmapFactory.decodeStream(stream);
stream.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

imageView.setImageBitmap(bitmap);

}
}

最佳答案

尝试一下

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
}
}

更多详情请访问Take a Photo with the Camera

关于java - 获取我的 Activity 结果的空数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22885121/

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