转载博客:https://blog.csdn.net/diligenttime/article/details/82118452

在image_album_show
设置String ip为全局变量
Intent intent= new Intent();
intent.setClass(image_album_show.this, MainActivity.class);//image_album_show和MainActivity连接起来 允许他们之间传递数据
intent.putExtra(“picture”,ip);//用putExtra把内容传送到另一个Activity,名字是picture,值是ip
startActivity(intent);//启动MainActivity并把intent传递过去
在image_album_show的displayImage中if下添加:ip=imagePath;

在MainActivity
添加一个imageveiw
设置 private ImageView picture1;
在protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    picture1 = (ImageView) findViewById(R.id.imageView);
    Button takePhoto = (Button) findViewById(R.id.take_photo);
    Button chooseFromAlbum = (Button) findViewById(R.id.choose_from_album);
   // Button takeVideo = (Button) findViewById(R.id.take_video);
  // Button showVideo = (Button) findViewById(R.id.show_videos);
    Intent inter=getIntent();

    String imagePath = inter.getStringExtra("picture");

    if (imagePath != null) {
        Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
        picture1.setImageBitmap(bitmap);
    }
    else {
        Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
    }

android studio 打开相册后通过路径显示图片

相关文章:

  • 2021-12-22
  • 2022-12-23
  • 2022-02-10
  • 2021-07-28
  • 2022-12-23
  • 2021-10-31
  • 2021-07-01
  • 2021-10-20
猜你喜欢
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案