0

I have a class where a photo is captured and Bitmap is stored in the ImageView. In another class I got brush tool (canvas). If I create a new Bitmap in a second class I can draw on canvas but I can't draw on the captured image from the first class. How could I move the bitmap from first class to another?

Method of the first class of captured image

protected void onActivityResult (int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    bitmap = (Bitmap) data.getExtras().get("data");
    imageView.setImageBitmap(bitmap);
}

Method of the second class with the brush tool and empty canvas

public void init(DisplayMetrics metrics) {
    int height = metrics.heightPixels;
    int width = metrics.widthPixels;
    mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    mCanvas = new Canvas(mBitmap);
    currentColor = DEFAULT_COLOR;
    strokeWidth = BRUSH_SIZE;
}
Vita
  • 13
  • 4
  • You have the bit map in the first class before you send it to `setImageBitmap` just put it in an object you can reach from both places and you are done. – Simson Dec 16 '19 at 02:38
  • you can call putExtra() on the Intent when you start the activity and call getExtrax() in the second class – DoFlamingo Dec 16 '19 at 08:19
  • Get the bitmap path as static field and then you able to use anywhere – Asad Mukhtar Dec 16 '19 at 20:54

2 Answers2

0

Save the bitmap and get its path. Now pass that path into your activity intent. Then retrieve it from other activity using intent.getExtras()

To save bitmap you can check this answer 'How to save a bitmap on internal storage'

If its not an activity then use set get methods

public void setBitmap( Bitmap b ) {
bitmap= b;

}

public Bitmap getBitmap() {
return bitmap;
}'

Check this tutorial for set get methods 'http://www.javawithus.com/tutorial/get-and-set-methods'

intellignt_idiot
  • 1,962
  • 2
  • 16
  • 23
0

Just take a one static variable of bitmap

Set your received bitmap into that variable and access that variable by its class name directly into your second activity.