0

I am using Bitmap b = Bitmap.createBitmap(mView.getDrawingCache()); for creating image from my view so I can than share it. It works perfectly but when mView is bigger then the phone screen I get a null pointer exeption:

 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference

Anyone knows how to fix this?

Johann
  • 27,536
  • 39
  • 165
  • 279
Tadej Vengust
  • 1,351
  • 4
  • 18
  • 35

1 Answers1

1

So I didn't find any way to get around this error so I created an image in a different way(by drawing on canvas):

int w = mView.getWidth();
int h = mView.getHeight();
Bitmap result = Bitmap.createBitmap(w, h,  Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result);
mView.draw(canvas);

Hope this helps anyone with the same problem.

Tadej Vengust
  • 1,351
  • 4
  • 18
  • 35