我正在研究允許用戶在滑動時遮擋部分位圖的應用程序。然後,當他完成滑動我調用一種方法來裁剪位圖的部分並執行一些功能(但裁剪的位圖不保存在任何地方,所以懷疑這裏有任何問題)。點擊imageView我用原始位圖重置位圖。還有一個功能來旋轉位圖。我有兩個位圖對象帳單(用戶實際上在它上面滑動)和billOrg(原始位圖)。以下是方法。修改位圖時的Android崩潰:jni_helper.cc:110位圖的格式錯誤:4
private void drawShade(float left,float top,float right,float bottom){
//this method draws shade on bitmap. Coordinates are sent from onTouchEvent
TAG = "drawShade";
//parseTouchPointsString();
Bitmap tempBitmap = Bitmap.createBitmap(bill.getWidth(), bill.getHeight(), Bitmap.Config.RGB_565);
Log.d(TAG,"bill:"+bill.isMutable()+"tempBit:"+tempBitmap.isMutable()+"");
Canvas tempCanvas = new Canvas(tempBitmap);
tempCanvas.drawBitmap(bill,0,0,null);
tempCanvas.drawRoundRect(new RectF(left,top,right,bottom), 10, 10, shadePaint);
imgView.setImageDrawable(new BitmapDrawable(getResources(), tempBitmap));
if(fingerUp) {
Log.e("fingerUp",fingerUp+"");
bill = tempBitmap;
}
Log.d(TAG,"shade drawn at:"+left+","+top+","+right+","+bottom);
}
這裏是方法旋轉位圖:
public void rotateImage(View v){
TAG = "rotateImage";
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotatedBitmap = Bitmap.createBitmap(bill , 0, 0, bill.getWidth(), bill.getHeight(), matrix, true);
bill = rotatedBitmap.copy(rotatedBitmap.getConfig(),true);
createScaledBitmap();
billOrg = bill.copy(rotatedBitmap.getConfig(),true);//bill.copy(bill.getConfig(),false);
setImage(bill);
rl.invalidate();
}
方法上點擊復位位:
private void resetImageView(boolean saveShade){
//the boolean var here tell whether to keep the shaded portion after reset or not
if(!saveShade) { //app crashes in this if block although I have try-catch.
try {
Canvas canvas = new Canvas(bill);
Log.e("resetImageView", "billOrg:" + billOrg.isMutable() + ",bill:" + bill.isMutable()); //returns true for both bitmap objects
canvas.drawBitmap(billOrg, 0, 0, null);
touchBounds = "";
tv_res.setText("");
rl.invalidate();
setImage(bill);
}catch(Exception ex){
Log.e("resetImage",ex.getMessage());
}
}else{
Canvas canvas = new Canvas(bill);
canvas.drawBitmap(bill, 0, 0, null);
touchBounds = "";
tv_res.setText("");
rl.invalidate();
setImage(bill);
}
}
全部是除了當用戶第一次刷卡圖像細膩 - >然後旋轉圖像 - >然後點擊位圖。 我得到的只是這個錯誤:jni_helper.cc:110位圖格式錯誤:4。沒有其他例外。 根據我所知的位圖通常會拋出錯誤,如果我們試圖修改位圖對象是不可變的,但我已經在所有地方使它變得可變。它也在日誌中打印可變。我想我在修改位圖的時候做錯了什麼。我知道可能會讓你感到困惑。我不知道我解釋得有多好。如果您需要任何清晰度,請提問。我需要一些幫助。