gpt4 book ai didi

android - 添加选项时 decodeResource 返回 null

转载 作者:行者123 更新时间:2023-11-29 16:04:25 25 4
gpt4 key购买 nike

您好,我正在使用以下方法将位图设置为 ImageView:

        o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
o.inDither = false;
o.inPurgeable = true;
o.inInputShareable = true;

b = BitmapFactory.decodeResource(getApplicationContext()
.getResources(), resourceId);
//Note the Options parameter is ignored
ivWallpaper = (ImageView) findViewById(R.id.ivWallpaper);
ivWallpaper.setImageBitmap(b);
ivWallpaper.setOnClickListener(Wallpapers.this);

效果很好,但是当我添加选项参数时:

        o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
o.inDither = false;
o.inPurgeable = true;
o.inInputShareable = true;

b = BitmapFactory.decodeResource(getApplicationContext()
.getResources(), resourceId, o);
ivWallpaper = (ImageView) findViewById(R.id.ivWallpaper);
ivWallpaper.setImageBitmap(b);
ivWallpaper.setOnClickListener(Wallpapers.this);

它在以下位置给了我一个 nullPointerException: ivWallpaper.setImageBitmap(b);

请帮帮我。几个小时以来一直在努力解决这个问题

最佳答案

http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html

公共(public) bool 值 inJustDecodeBounds

如果设置为 true,解码器将返回 null(无位图),但 out... 字段仍将被设置,允许调用者查询位图而无需为其像素分配内存。

关于android - 添加选项时 decodeResource 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20693276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com