android projrct中的图像变形

时间:2017-08-24 03:12:12

标签: android

在我的Android应用程序中,我需要将图像从一个点变形到另一个点。 它应该是那样的

enter image description here

原点A和B是A

的新位置

结果可能就是这样 enter image description here

我尝试使用" drawBitmapMesh"功能使它成为可能,但没有达到,这里是包装代码:

public void warp(float startX,float startY,float endX,float endY){

        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();
    }

1 个答案:

答案 0 :(得分:0)

最后我自己解决了,我使用Android的GPUimage并用GLSL编写了一个定制的过滤器,效果很好〜!