2017-08-24 119 views
0

在我的android應用程序中,我需要將圖像從一個點變形到另一個點。 它應該看起來像在android項目中的圖像變形

enter image description here

原點A和B是的

新位置的結果可能喜歡 enter image description here

我嘗試使用「drawBitmapMesh」函數使其成爲可能,但沒有達到,這裏是包裝代碼:

公共無效經線(浮startx的,浮動startY,浮endX,浮動恩迪){

 float ddPull = (endX - startX) * (endX - startX) + (endY - startY) * (endY - startY); 
     float dPull = (float) Math.sqrt(ddPull); 

     for (int i = 0; i < (COUNTS * 2); i += 2) { 
      float dx = orig[i] - startX; 
      float dy = orig[i + 1] - startY; 
      float dd = dx * dx + dy * dy; 
      float d = (float) Math.sqrt(dd); 

      // do deformation when the point is in the circle 
      if (d < cirR) { 
       double e =(cirR * cirR - dd) * (cirR * cirR - dd)/((cirR * cirR - dd + dPull * dPull) * (cirR * cirR - dd + dPull * dPull)); 
       double pullX = e * (endX - startX); 
       double pullY = e * (endY - startY); 

       verts[i] = (float) (orig[i] + pullX); 
       verts[i + 1] = (float) (orig[i + 1] + pullY); 

      } 
     } 

     invalidate(); 
    } 

回答

0

最後我解決這個問題由我自己,我用的是GPUimage爲Android寫的GLSL定製過濾器,它的工作好〜!