2016-04-23 81 views
0

我一直在努力擺脫這種異常,我的問題是每次我嘗試重新構建我的形象,並將其定位在我的framelayout我得到這個錯誤,在我檢查圖像是否爲null之前,如果沒有,那麼我會繼續前進,並且在我調用.createBitmap方法之前,我正在測量其尺寸總是似乎爲>0,但.createBitmap方法仍會拋出例外,這是我的代碼:IllegalArgumentException:寬度和高度必須> 0與bitmap.createBitmap方法

framelayout.post(new Runnable() { 
     @Override 
     public void run() { 

      original = getBitmap(); 
      if (original != null) { 
       //where exception occurs 
       setBitmap(original); 
      } 
     } 
    }); 

    private void setBitmap(Bitmap original) { 

    Bitmap scaledBitmap = scaledBitmap(original, sourceFrame.getWidth(), frameLayout.getHeight()); 
    sourceImageView.setImageBitmap(scaledBitmap); 
    Bitmap tempBitmap = ((BitmapDrawable) frameLayout.getDrawable()).getBitmap(); 
    Map<Integer, PointF> pointFs = getEdgePoints(tempBitmap); 
    polygonView.setPoints(pointFs); 
    polygonView.setVisibility(View.VISIBLE); 
    int padding = (int) getResources().getDimension(R.dimen.scanPadding); 
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(tempBitmap.getWidth() + 2 * padding, tempBitmap.getHeight() + 2 * padding); 
    layoutParams.gravity = Gravity.CENTER; 
    polygonView.setLayoutParams(layoutParams); 
} 

    private Bitmap scaledBitmap(Bitmap bitmap, int width, int height) { 
    Matrix m = new Matrix(); 
    //dimensions are always greater than 0 when an image is picked 
    //but still throws exception 
    System.out.println("bitmap height: "+bitmap.getHeight()); 
    System.out.println("bitmap Width: "+bitmap.getWidth()); 
    m.setRectToRect(new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()), new RectF(0, 0, width, height), Matrix.ScaleToFit.CENTER); 

     //exception occurs here 
     return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); 

} 

在這一點上我很困惑,我不知道該怎麼辦。

回答

0

錯誤是由我從圖庫中挑選圖像的方法造成的,它看起來不是挑選,並且它是否有趣的事情正在發生。

相關問題