2013-05-02 41 views
0

我正在處理圖像編輯應用程序並卡在這裏。在縮放中繪製路徑的行爲不一致Android

public void onDraw(Canvas canvas) { 
    // TODO Auto-generated method stub 
    super.onDraw(canvas); 
    // int width=this.getDrawable().getIntrinsicWidth(); 
    // int height=this.getDrawable().getIntrinsicHeight(); 
    // float sw=((float)getBitmapRect().width())/width; 
    // float sh=((float)getBitmapRect().height())/height; 
    matrix = new Matrix(); 
    // matrix.postScale(sw, sh); 

    canvas.setMatrix(getDisplayMatrix()); 
    canvas.concat(matrix); 
    canvas.save(); 
    if (MainActivity.checkBtnOn == MainActivity.BSS_ONE) { 
     for (Pair<Path, Float> p : foregroundPaths) { 
      mPaint.setStrokeWidth(p.second); 
      canvas.drawPath(p.first, mPaint); 
     } 

    } else if (MainActivity.checkBtnOn == MainActivity.BSS_TWO) { 
     for (Pair<Path, Float> p : foregroundPaths) { 
      mPaint.setStrokeWidth(p.second); 
      canvas.drawPath(p.first, mPaint); 
     } 
    } else { 
     for (Pair<Path, Float> p : foregroundPaths) { 
      mPaint.setStrokeWidth(p.second); 
      canvas.drawPath(p.first, mPaint); 
     } 
    } 

    // matrix.postScale(getScale(), getScale()); 
    rect = canvas.getClipBounds(); 
    displayRectF = new RectF(rect.left, rect.top, rect.right, rect.bottom); 
    // rect =drawable.getBounds(); 


    canvas.restore(); 

} 

without zoom image

with zoom image

我的問題是 「什麼,我做錯了,導致我繪製的路徑不一致的行爲。」意味着它在縮放時的位置變化(對於我正在使用sephiroth庫的縮放)。我附加了兩個圖像鏈接。第一張圖像適合屏幕和第二張縮放。

請幫助我或任何建議,將不勝感激。 感謝

回答

1

問題解決 我剛纔刪除

canvas.setMatrix(getDisplayMatrix()); //removed 

    canvas.concat(getDisplayMatrix()); //add 
+0

無需setMatrix到畫布上。 – 2013-05-08 08:52:18