0

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 ?

Coolalien
  • 49
  • 1
  • 1
  • 7
  • If the bitmap is null, then this code is not the reason for that. Most likely your activity has been destroyed in the meantime and your bitmap has been recycled, so check for the path where you get the bitmap from. – Thomas Keller Feb 28 '16 at 11:17
  • @ThomasKeller there is no null bitmap . – Coolalien Feb 28 '16 at 11:23
  • Sure there is, the exception points you to exactly that: "'int android.graphics.Bitmap.getWidth()' on a null object reference" – Thomas Keller Feb 28 '16 at 11:24

0 Answers0