2012-02-29 74 views
0

我有一個應用程序,我有一個表面視圖。在這個表面視圖中,我一次最多顯示兩個位圖,這些位圖來自短片。我有這個工作正常,但我允許用戶縮放和平移圖像/剪輯。我想在垂直方向上平分屏幕,我會讓一個剪輯拍攝屏幕的上半部分,另一個剪輯拍攝下半部分。由於這是一個曲面視圖,因此這些視圖沒有實際的分離。將圖像放大設置範圍內

當前我繪製的第二個位圖,如果它跨越虛擬邊界的屏幕不動產然後它被覆蓋在另一個位圖上。我想剪掉跨越邊界的圖像部分,是否有人知道我在畫布上繪圖時如何執行此操作?

回答

0

我想到了這一點,我會在這裏發佈答案,以防其他人遇到類似的情況。我正在做的是類似於以下內容。我爲這些畫布對象創建了新的畫布對象以及一個可寫入的位圖。然後,我可以在各個畫布對象上執行任何繪圖和轉換,然後將這些繪製到我的SurfaceView的主畫布上。

if(workingBitmap==null){ 
     workingBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight()/2, Bitmap.Config.ARGB_4444); 
     c.setBitmap(workingBitmap); 
     workingBitmap2 = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight()/2, Bitmap.Config.ARGB_4444); 
     c2.setBitmap(workingBitmap2); 
    } 

    super.onDraw(canvas); 
    canvas.drawColor(Color.BLACK); 
    c.drawBitmap(bitmap, 0,0,null); 
    c2.drawBitmap(bitmap2, 0,-100,null); 
    canvas.drawBitmap(workingBitmap, 0,0,null); 
    canvas.drawBitmap(workingBitmap2, 0,canvas.getHeight()/2,null); 
1

參數

 private float dx; // postTranslate X distance 
    private float dy; // postTranslate Y distance 
    private float[] matrixValues = new float[9]; 
    float matrixX = 0; // X coordinate of matrix inside the ImageView 
    float matrixY = 0; // Y coordinate of matrix inside the ImageView 
    float width = 0; // width of drawable 
    float height = 0; // height of drawable 

變化

 case MotionEvent.ACTION_MOVE: 
     if (mode == DRAG) { // movement of first finger 

     // matrix.set(savedMatrix); 
      //. 
      matrix.set(savedMatrix); 

       matrix.getValues(matrixValues); 
       matrixX = matrixValues[2]; 
       matrixY = matrixValues[5]; 
       width = matrixValues[0] * (((ImageView) view).getDrawable() 
             .getIntrinsicWidth()); 
       height = matrixValues[4] * (((ImageView) view).getDrawable() 
             .getIntrinsicHeight()); 

       dx = event.getX() - start.x; 
       dy = event.getY() - start.y; 

       //if image will go outside left bound 
       if (matrixX + dx < 0){ 
        dx = -matrixX; 
       } 
       //if image will go outside right bound 
       if(matrixX + dx + width > view.getWidth()){ 
        dx = view.getWidth() - matrixX - width; 
       } 
       //if image will go oustside top bound 
       if (matrixY + dy < 0){ 
        dy = -matrixY; 
       } 
       //if image will go outside bottom bound 
       if(matrixY + dy + height > view.getHeight()){ 
        dy = view.getHeight() - matrixY - height; 
       } 
       matrix.postTranslate(dx, dy); 
      //... 

    //    if (view.getLeft() >= -392) { 
    //     matrix.postTranslate(event.getX() -    start.x, event.getY() 
    //       - start.y); 
     // 
    //    } 
     } else if (mode == ZOOM) { // pinch zooming 
      float newDist = spacing(event); 
      Log.d(TAG, "newDist=" + newDist); 
      if (newDist > 5f) { 
       matrix.set(savedMatrix); 
       scale = newDist/oldDist; // thinking i need to play around 
              // with this value to limit it** 
       matrix.postScale(scale, scale, mid.x, mid.y); 
      } 
     } 

     break;