2011-05-05 37 views
0

我看到這個錯誤是通過亂七八糟的報告,但不知道它可能涉及或如何找到錯誤可能在我的Android代碼。Android android.graphics.Bitmap.checkPixels訪問錯誤

class java.lang.IllegalArgumentException 
Msg: android.graphics.Bitmap.checkPixelsAccess:823 (x + width must be <= bitmap.width()) 

有沒有人有一個想法這可能涉及什麼樣的錯誤?

回答

4

您的代碼必須事先包含對方法的調用:

yourBitmap.getPixels (pixels, offset, stride, x, y, width, height);

例外由於拋出這樣的事實:

你的起點x座標+你想從搶量當前行,超出您的源位圖寬度。

這裏是一個圖片,可能更好地解釋這種情況:

enter image description here

希望這有助於。 此致敬禮。

0
 //encoding method 
     Bitmap encodeAsBitmap(String str) throws WriterException { 
     int black = 0xFF000000; 
     int white = 0xFFFFFFFF; 

     int width=400; 
     int height=400; 

      BitMatrix result; 
      Bitmap bitmap=null; 
      try { 
       result = new MultiFormatWriter().encode(str, 
         BarcodeFormat.QR_CODE,height ,width , null); 

       int w = result.getWidth(); 
       int h = result.getHeight(); 
       int[] pixels = new int[w * h]; 
       for (int y = 0; y < h; y++) { 
        int offset = y * w; 
        for (int x = 0; x < w; x++) { 
         pixels[offset + x] = result.get(x, y) ? black : white; 
        } 
       } 
       bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); 
//Use the same value of the height and width respectively  
       bitmap.setPixels(pixels, 0, 400, 0, 0, 400, 400); 
      } catch (Exception iae) { 
       iae.printStackTrace(); 
       return null; 
      } 
      return bitmap; 
     }