Passing image from one activity another activity

how to send image from one activity to another in android example
how to pass bitmap image from one activity to another in android
pass image from recyclerview to another activity
pass captured image to another activity
how to pass drawable image from one activity to another in android
how to pass image uri from one activity to another in android
how to pass image from listview to another activity in android
android select image from gallery and display in another activity

There are similar questions on SO, but none worked for me.

I want to fetch clicked image in Activity1 and display it in Activity2.I'm fetching image id of clicked image like this:

((ImageView) v).getId()

and passing it through intent to another activity.

In 2nd activity, I use image id as following:

imageView.setImageResource(imgId);

I logged the value og image id in both the activities and it's same.

But I'm getting following exception:

android.content.res.Resources$NotFoundException: Resource is not a Drawable 
(color or path): TypedValue{t=0x12/d=0x0 a=2 r=0x7f050000}

I guess the problem here is getId() is returning Id of ImageView and not of it's source image. All these images are present in drawable.

Any help appreciated.

There are 3 Solutions to solve this issue.

1) First Convert Image into Byte Array and then pass into Intent and in next activity get byte array from Bundle and Convert into Image(Bitmap) and set into ImageView.

Convert Bitmap to Byte Array:-

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Pass byte array into intent:-

Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);

Get Byte Array from Bundle and Convert into Bitmap Image:-

Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);

image.setImageBitmap(bmp);

2) First Save image into SDCard and in next activity set this image into ImageView.

3) Pass Bitmap into Intent and get bitmap in next activity from bundle, but the problem is if your Bitmap/Image size is big at that time the image is not load in next activity.

When I click on ImageView, how can it show the same image in Next , How do I move a bitmap image from one activity to another? Using this you can pass bitmap to another activity. If you are using drawable than convert that drawable to bitmap first. Bitmap bitmap = ((BitmapDrawable)d).getBitmap(); For passing that bitmap to another activity using intent use this below code snippet. intent.putExtra("Bitmap", bitmap); And for fetch that bitmap intent in another activity

This won't work. You have to try it this way.

Set the DrawingCache of your ImageView to be true and then save the background as a Bitmap and pass it via putExtra.

image.setDrawingCacheEnabled(true);
Bitmap b=image.getDrawingCache();
Intent i = new Intent(this, nextActivity.class);

i.putExtra("Bitmap", b);
startActivity(i);

And in your Next Activity,

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("Bitmap");
imageView.setImageBitmap(bitmap);

How to pass drawable between activities, This example demonstrates how to do I pass an image from one Activity in android.Step 1 − Create a new project in Android Studio, go to File  If the image is too large and you can't save&load it to the storage, you should consider just using a global static reference to the bitmap (inside the receiving activity), which will be reset to null on onDestory, only if "isChangingConfigurations" returns true.

Define a Drawable static variable in your Application class, and then set image drawable data in the first activity, then in your next activity get data from the static variable you defied in your Application class.

public class G extends Application {
   public static Drawable imageDrawable;

   ...
}

First activity:

G.imageDrawable = imageView.getDrawable();

SecondActivity:

imgCamera.setImageDrawable(G.imageDrawable);

and in onDestroy:

@Override
protected void onDestroy() {
    G.imageDrawable = null;
    super.onDestroy();
}

Note: You have to define your Application class in the manifest:

<application
        android:name=".G"
        ...>

</application>

In this video I have shown how to pass the image from one activity to another using Intent Duration: 6:16 Posted: 23 Sep 2017 Hi friends, Here is my code for selecting datas from myql database with the help of php.All i want to do is i want to pass and display image through intent from Activity 1 to Activity 2.im new in android so please help me.

If you are moving from class like addapter class then use this code.

Bitmap bitImg=listItem.getBitmapImage();
    ByteArrayOutputStream baoS = new ByteArrayOutputStream();
    bitImg.compress(Bitmap.CompressFormat.JPEG, 50, baoS);
    intent.putExtra("bitArray", baoS.toByteArray());
    context.getApplicationContext().startActivity(intent);

and then past this to next activity

if(getIntent().hasExtra("bitArray")) {                
Bitmap bitM = BitmapFactory.decodeByteArray( getIntent().getByteArrayExtra("bitArray"),0,getIntent().getByteArrayExtra("bitArray").length);       
        imgIT = findViewById(R.id.img_detail);
        imgIT.setImageBitmap(bitM);
    }

How to pass Bitmap images from one activity to another Take your app to the top keyword Duration: 6:07 Posted: 22 Aug 2015 I was making an application where I chose image file using browser intent and process it using OpenCV NDK. I decided to keep a different Activity for the OpenCV part and hence I had to pass the bitmap data from my main Activity to the OpenCV part activity. I had written an application before where I starting one intent from another activity. But I did not know how to pass arguments to the new

The perfect way to do this in short. This is the code of sender .class file

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher;
Intent intent = new Intent();
Intent.setClass(<Sender_Activity>.this, <Receiver_Activity.class);
Intent.putExtra("Bitmap", bitmap);
startActivity(intent);

and this is receiver class file code.

Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
ImageView viewBitmap = (ImageView)findViewById(R.id.bitmapview);
viewBitmap.setImageBitmap(bitmap);

No need to compress. that's it

in this Video We Will Build an App that can Transfer Image Data Between Activities in Android Duration: 33:36 Posted: 27 Oct 2019 Pass edittext value to another activity in android.Send EditText entered selected data to another android activity Onbutton click receive+set into textview. Skip to content Home

Passing Images between Activities in Android. January 07, 2013. in First Activity: Intent intent=new putInt("image",R.drawable.ic_launcher); intent. another method: in First Activity: Drawable Get a single record from SQLite in ANDROID​. How to Pass Data from One Activity to Another in Android Method 1: Using Intent. We can send data while calling one activity from another activity using intent. All we have to do is add the data to Intent object using putExtra() method. The data is passed in key value pair. The value can be of types like int, float, long, string, etc. Sending Data

Passing image from one activity another activity. this should help you, however it will help when both the sender and reciver are activities, in case of fragments  See the code snippet below and ask if you have any doubt. Hope this helps.All the Best.

I have a main activity in which i am using custom listview(showing movie_poster,​movie_name,movie_rating)and i want that if i click on a row a 

Comments
  • Exactly it seems that problem: "I guess the problem here is getId() is returning Id of ImageView and not of it's source image." How do you retrive this image? why you can not get the image? is not in drawables? these image is from Internet. If the image is from internet you can try to cache the image on memory or on a file, and retrive it on the next activity by putting the cached
  • so how do I get RESOURCE ID ???
  • @Andro Selva solutions seems good :)
  • see this one [stackoverflow.com/questions/2139134/… ](stackoverflow.com/questions/2139134/…)
  • @GAMA Please see my answer and if you have any queries then tell me.
  • @GAMA if u are directly pass bitmap into intent and if image is big at that time the bitmap is not display in next activity so passing byte array is safe.
  • wait, this line won't work for me as u r giving hard-coded id of the image... Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
  • i have multiple images in activity 1, i want to ONLY display clicked image in activity2. so i can't give hard-coded image id.
  • I SOLVED THE PROBLEM by passing Resource Id of the image, Thnx anyways.
  • @GAMA If you can post how you solved it by passing Resource ID of the image, it will also be helpful (If you remember it)
  • I'm getting E/JavaBinder(61): !!! FAILED BINDER TRANSACTION !!! AND ANR in com.galley.sample (com.galley.sample/.ViewDetails) ... Reason: keyDispatchingTimedOut