Thursday, 19 September 2013

NullPointerException in createBitmap() from View

NullPointerException in createBitmap() from View

I am using the below code for getting a Bitmap from a View :
private static Bitmap loadBitmapFromView(View yourView) {
Bitmap snapshot = null;
Drawable drawable = null;
yourView.setDrawingCacheEnabled(true);
yourView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
//Quality of the snpashot
try {
snapshot = Bitmap.createBitmap(yourView.getDrawingCache());
drawable = new BitmapDrawable(snapshot);
} finally {
yourView.setDrawingCacheEnabled(false);
}
return snapshot;
}
But I am getting NullPointerException on the following line:
snapshot = Bitmap.createBitmap(yourView.getDrawingCache());

No comments:

Post a Comment