2017-08-24 33 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定制过滤器,它的工作好〜!