How to send image from one activity to another in android?

前端 未结 8 1867
忘掉有多难
忘掉有多难 2020-12-10 08:18

I am having a imageView in one class and on clicking the imageView a dialog box appear which has two option to take a image from camera or open the image gallery of device.

相关标签:
8条回答
  • 2020-12-10 09:00

    You get Image in your Activity as a Bitmap and you also pass that to another Activity as Bitmap with Intent.putExtra() like this:

    First Activity.

    Intent intent = new Intent(this, SecondActivity.class);
    intent.putExtra("bmp_Image", bmp); 
    

    and get from second Activity like:

    Bitmap bmp = (Bitmap) intent.getParcelableExtra("bmp_Image"); 
    

    you don't need to get url and load from url.

    that is the simplest way to pass the captured image from one Activity to another Activity.

    0 讨论(0)
  • 2020-12-10 09:01

    Take One Global.class and Declare public static Bitmap bmp;

    takeImg.setOnTouchListener(new OnTouchListener() {
    
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-generated method stub
                    if(event.getAction() == event.ACTION_UP)
                    {
                        i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        startActivityForResult(i,cameraData);
                    }
                    return true;
                }
            });
        }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            if(resultCode==RESULT_OK)
            {
                Bundle extras=data.getExtras();
                Global.bmp=(Bitmap)extras.get("data");
            }
        }
    

    And When u want to use Bitmap bitmap = Global.bmp ;

    0 讨论(0)
提交回复
热议问题