2013-12-19 25 views
1

您好我正在使用此设置一个位图到ImageView的返回null:decodeResource当选项被添加

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

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

回答

4

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

公共布尔inJustDecodeBounds

如果设置为true,解码器将返回null(无位),但出来...领域仍将设置,允许调用者查询位图而不必为其像素分配内存。

+0

这非常简单。谢谢。 –

+0

@InnenTensai:如果这个答案回答了你的问题,考虑接受它会给海报带来15分。 1 +从我投票。 **编辑**没关系 - 你只是做到了!不错的演出! –

相关问题