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);
}
在這一點上我很困惑,我不知道該怎麼辦。