0

我正在使用Bitmap b = Bitmap.createBitmap(mView.getDrawingCache());从我的视图中创建图像,所以我可以分享它。它工作得很好,但是当 mView 比手机屏幕大时,我得到一个空指针异常:

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

任何人都知道如何解决这个问题?

4

1 回答 1

1

所以我没有找到任何方法来解决这个错误,所以我以不同的方式创建了一个图像(通过在画布上绘图):

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);

希望这可以帮助任何有同样问题的人。

于 2016-02-08T11:17:46.053 回答