2013-12-19 27 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 +從我投票。 **編輯**沒關係 - 你只是做到了!不錯的演出! –

相關問題