gpt4 book ai didi

java - 我如何从图库中选择图像并在另一个 Activity 中显示该图像......?

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

我已经创建了从图库中选择图像的代码,但我无法通过 bundle 将该值传递给另一个 Activity ..请帮助我

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);


enter code here

我需要将 SelectedImageUri 作为 bundle 传递给另一个 Activity

最佳答案

使用这个

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
img.setImageURI(selectedImageUri);
Intent intent = new Intent(this , Second_activity.class );
intent.putExtra("image_path", selectedImagePath);
startActivity(intent);
}

它将启动第二个 Activity ,然后在第二个 Activity 上通过此接收这些值

 Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("image_path");
//use value
}

关于java - 我如何从图库中选择图像并在另一个 Activity 中显示该图像......?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24839332/

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