I'm trying to resize bitmap............on click its working bt in idle time when click on view..." 'int android.graphics.Bitmap.getWidth()' on a null object reference " this error occurs. here is resize code for my bitmap...........how to solve this ??
public static Bitmap resizeImage(Bitmap source, int w, int h) {
int width = source.getWidth();
int height = source.getHeight();
float scaleWidth = ((float) w) / width;
float scaleHeight = ((float) h) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
return Bitmap.createBitmap(source, 0, 0, width, height, matrix, true);
}
code :
public static int getScreenWidth() {
WindowManager wm = (WindowManager) FusionMusicApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
return wm.getDefaultDisplay().getWidth();
}
here is usage code:
bitmap = resizeImage(bitmap, getScreenWidth()/2, getScreenWidth()/2);
how to fix this ?