在空对象引用上的Android-'int android.graphics.Bitmap.getWidth()'

时间:2016-02-28 10:57:19

标签: android bitmap height

我正在尝试调整位图的大小............单击视图时单击它在空闲时间工作的bt ...“'int android.graphics.Bitmap.getWidth()'在空对象引用上“发生此错误。 这里是调整我位图的代码...........如何解决这个问题?

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

代码:

    public static int getScreenWidth() {
    WindowManager wm = (WindowManager) FusionMusicApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
    return wm.getDefaultDisplay().getWidth();
}

这是使用代码:

bitmap = resizeImage(bitmap, getScreenWidth()/2, getScreenWidth()/2);

如何解决这个问题?

0 个答案:

没有答案