简体   繁体   中英

Passing ImageView from one activity to another activity

I have been trying to create an android app with the integration of Adobe creative SDJ but I have encountered some problems.

I have created an Activity where one launches camera or gallery to select an image for editing it. The camera launches and the photo is captured and saved in this path:

storage/emulated/0/Pictures/myAppName/myImage.jpg

It is also supposed to be displayed in an ImageView in the same activity but it isn't being displayed. In another activity, I have integrated the ImageEditing UI of the creative sdk from Adobe which needs an imageUri as an input image.

Here are my codes for displaying Image in the ImageView :

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
        // camera codes 
        String path = "storage/emulated/0/Pictures/Touch/touch.jpg";
        resultImageView.setImageDrawable(Drawable.createFromPath(path));

        // gallery codes
        if (resultCode == RESULT_OK && requestCode == PICK_IMAGE){
            imageUri = data.getData();
            resultImageView.setImageURI(imageUri);
        }
    }

How can I convert the ImageView into Uri and send it to the next activity? Thanks in advance!

I think you are doing wrong for camera code. as you say your gallery code is working fine .try this:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try{
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == 0) {
                //taking clicked image from Intent of activity
                Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();

                File destination = new File(Environment.getExternalStorageDirectory(),
                        System.currentTimeMillis() + ".jpg");//storing image 

                FileOutputStream fo;
                try {
                    destination.createNewFile();
                    fo = new FileOutputStream(destination);
                    fo.write(bytes.toByteArray());
                    fo.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
 //adding clicked image to ImageView
 imgClicked.setImageBitmap(thumbnail);

Hope this will help you..:-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM