我需要解码.png图像以将其用作创建一些Rect的基础,并将图像本身用作我的应用程序的背景,但是try-catch不断抛出Null Pointer Exception,这是代码:
try {
InputStream is = ParamsSingleton.assetManager.open("background.png");
figure = BitmapFactory.decodeStream(is);
height = figure.getHeight();
width = figure.getWidth();
src = new Rect(0, 0, width, height);
first = new Rect();
} catch (IOException e) {
Log.d(TAG, "Image decode fail!");
}
我已经尝试了一些日志,并在InputStream行上尝试了try-catch中断,并在catch块中打印了'Log.d',我检查了文件名,没事。
您可以直接在getAssets.open
中使用decodeStream
方法。