How to move image captured with the phone camera from one activity to an image view in another activity?

后端 未结 3 1112

The first activity has a button which when clicked, opens the inbuilt camera. Now when the picture is taken, a new activity opens with the image captured in an imageVi

3条回答
  •  时光取名叫无心
    2020-12-21 09:15

    there are several ways to do accomplish this, via sending the bitmap itself within Intent (Not Recommended) or you save the image to the storage and send its path within the intent which is recommended. first you save the image to the SDCARD and then pass it within the intent for example

    Intent intent = new Intent(this,MyClass.class);
    Bundle bundle = new Bundle();
    bundle.putString("IMAGE_PATH",imageFile);
    intent.putExtras(bundle);
    startActivity(intent);
    

    and then in the other activity you could use

    String path = getIntent().getExtras().getString("IMAGE_PATH");
    Bitmap bmp = BitmapFactory.decodeFile(path);
    myImage.setImageBitmap(bmp);
    

提交回复
热议问题