Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.PointF; public class Main { public static void barrelDistortion(double paramA, double paramB, double paramC, PointF src) { double paramD = 1.0 - paramA - paramB - paramC; // describes the linear scaling of the image float d = 1.0f; // center of dst image double centerX = 0f; double centerY = 0f; if (src.x == centerX && src.y == centerY) { return; } // cartesian coordinates of the destination point (relative to the centre of the image) double deltaX = (src.x - centerX) / d; double deltaY = (src.y - centerY) / d; // distance or radius of dst image double dstR = Math.sqrt(deltaX * deltaX + deltaY * deltaY); // distance or radius of src image (with formula) double srcR = (paramA * dstR * dstR * dstR + paramB * dstR * dstR + paramC * dstR + paramD) * dstR; // comparing old and new distance to get factor double factor = Math.abs(dstR / srcR); // coordinates in source image float xResult = (float) (centerX + (deltaX * factor * d)); float yResult = (float) (centerY + (deltaY * factor * d)); src.set(xResult, yResult); } }