-2

//this is code where i get the image from previous activity

i = getIntent();
getimage = i.getStringExtra("uri");

BitmapFactory.Options options = new BitmapFactory.Options();

options.inSampleSize = 6;

Bitmap bitmap = BitmapFactory.decodeFile(getimage, options);

Log.e("arun", "arun" + bitmap);

imageView.setImageBitmap(bitmap);

//now how i send it to next activity to show this in imageview of next activity //in next activity i have write

bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
previewThumbnail.setImageBitmap(bitmap);

//but error occur

Udo Held
  • 12,314
  • 11
  • 67
  • 93
  • refer this link https://stackoverflow.com/questions/11519691/passing-image-from-one-activity-another-activity – Sagar Patel Aug 21 '17 at 11:32
  • you can pass url from activity 1 to activity 2 and load it again in your imageview. – MPG Aug 21 '17 at 11:35

4 Answers4

1

Use below code for sending and Receiving Bitmap

For Sending Bitmap :

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImg", bitmap);

For Receiveing Bitmap use getParcelableExtra() Method

Intent intent = getIntent(); 
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImg");
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
0

Your first activity

Intent intent = new Intent(this, Activity.class);
intent.putExtra("bitmap", bitmap);

Second activity

 Bitmap bitmap = getIntent().getParcelableExtra("bitmap");
yourimageview.setImageBitmap(bitmap);
Sagar Patel
  • 224
  • 1
  • 9
0

First.Java

imageView.buildDrawingCache();
Bitmap image= imageView.getDrawingCache();

Bundle bd = new Bundle();
bd.putParcelable("imagemap", image);
intent.putExtras(extras);
startActivity(intent);

Second.Java

Bundle bd = getIntent().getExtras();
Bitmap bitmp = (Bitmap) extras.getParcelable("imagemap");
image.setImageBitmap(bmp);
Harshit Trivedi
  • 764
  • 9
  • 33
-1

you can make one singleton class for the image passing here, may share code can you please show it.

public class DataTransaction {

    private static volatile DataTransaction instance = null;
    private Bitmap bitmap;

    private DataTransaction() {
    }

    public static DataTransaction getInstance() {
        if (instance == null) {
            synchronized (DataTransaction.class) {
                if (instance == null) {
                    instance = new DataTransaction();
                }
            }
        }
        return instance;
    }

    public Bitmap getBimap() {
        return mapView;
    }

    public void setBimap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }
}

Use:

DataTransaction model = DataTransaction.getInstance();
model.setBitmap(...);

Bitmap bitmap = DataTransaction.getInstance().getBimap();
Kishan Donga
  • 2,851
  • 2
  • 23
  • 35
  • //i have use this code to get image from image view imageView.buildDrawingCache(); Bitmap bitmap = imageView.getDrawingCache(); Intent intent = new Intent(SecondActivity.this, FilterActivity.class); intent.putExtra("BitmapImage", bitmap); startActivity(intent); //and i have use code in next activity Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImg"); but ihave get an error of null pointer in getparceble extera – Archna Sony Aug 21 '17 at 11:43
  • you just replace intent.putExtra("BitmapImage", bitmap) this line with DataTransaction model = DataTransaction.getInstance(); model.setBitmap(...); and when open your second activity then Bitmap bitmap = DataTransaction.getInstance().getBimap(); – Kishan Donga Aug 21 '17 at 11:46
  • This solution is efficient because of no need to cast each and every time your Parcelable data to bitmap. – Kishan Donga Aug 21 '17 at 11:48