gpt4 book ai didi

java - 如何将图像传输到另一个 Activity

转载 作者:行者123 更新时间:2023-12-01 16:57:51 25 4
gpt4 key购买 nike

我有两个 Activity ,第一个是按钮,它调用 void openCamera,第二个是我需要获取位图。
我有两个问题:
1、哪一行代码是保存图片?
2. 如何从 OnActivityResult 获取位图并在另一个 Activity 中获取它?

private void openCamera() {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "Taking pic from the Camera");
image_uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, image_uri);
startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
}

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

SelectedImage.setImageURI(image_uri);
try {
Bitmap ImageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), image_uri);
detectImage(ImageBitmap);
} catch (IOException e) {
e.printStackTrace();
}
}

最佳答案

不要考虑通过Bundle传递它(文档:https://developer.android.com/guide/topics/resources/runtime-changes.html#RetainingAnObject)

我认为,您应该将图像保存在应用程序的内部存储中,然后将其加载到第二个 Activity 中。以下是解释如何执行此操作的答案:Saving and Reading Bitmaps/Images from Internal memory in Android

关于java - 如何将图像传输到另一个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61558063/

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