[PNG图像和Android中的InputStream

问题描述 投票:0回答:1

我需要解码.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',我检查了文件名,没事。

java android nullpointerexception inputstream
1个回答
1
投票

您可以直接在getAssets.open中使用decodeStream方法。

© www.soinside.com 2019 - 2024. All rights reserved.