我想在画布上画一幅画,但当我打电话时:
Bitmap android_guy = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher), 50, 50, true);`我得到以下错误:
由: java.lang.NullPointerException:尝试在android.graphics.Bitmap.createScaledBitmap(Bitmap.java:702)`上对空对象引用调用虚拟方法'int android.graphics.Bitmap.getWidth()‘引起的
我不把这个方法称为int android.graphics.Bitmap.getWidth()。
有人能解释为什么它给了我这个错误,或者向我建议另一种方法将图像转换成位图吗?
发布于 2018-03-21 20:44:18
像这样试试
Bitmap.createScaledBitmap(BitmapFactory.decodeResource(context.getResources(),getResources().getDrawable(R.mipmap.ic_launcher),50,50, true);如果getResources().getDrawable(R.mipmap.ic_launcher)生成错误,请尝试context.getResources().getDrawable(R.mipmap.ic_launcher)
https://stackoverflow.com/questions/49416076
复制相似问题