我正在尝试在 Android 中的位图图像上实现鱼眼效果。是否有现有的库或算法可以提供帮助?
问问题
3576 次
3 回答
6
我推荐你使用 Android Media Effects API。如果您想对效果进行更多控制(或针对较旧的 Android 版本),您还可以直接使用 opengl 将鱼眼效果应用于您的照片。有关该主题的一些教程:http: //www.learnopengles.com/android-lesson-four-introducing-basic-texturing/。学习 opengl 将使您能够对照片应用各种效果,着色器代码可以在互联网上轻松找到(例如:https ://github.com/BradLarson/GPUImage/tree/master/framework/Source )
这是鱼眼效果的着色器代码:
private static final String FISHEYE_FRAGMENT_SHADER =
"precision mediump float;\n" +
"uniform sampler2D u_Texture;\n" +
"uniform vec2 vScale;\n" +
"const float alpha = float(4.0 * 2.0 + 0.75);\n" +
"varying vec2 v_TexCoordinate;\n" +
"void main() {\n" +
" float bound2 = 0.25 * (vScale.x * vScale.x + vScale.y * vScale.y);\n" +
" float bound = sqrt(bound2);\n" +
" float radius = 1.15 * bound;\n" +
" float radius2 = radius * radius;\n" +
" float max_radian = 0.5 * 3.14159265 - atan(alpha / bound * sqrt(radius2 - bound2));\n" +
" float factor = bound / max_radian;\n" +
" float m_pi_2 = 1.570963;\n" +
" vec2 coord = v_TexCoordinate - vec2(0.5, 0.5);\n" +
" float dist = length(coord * vScale);\n" +
" float radian = m_pi_2 - atan(alpha * sqrt(radius2 - dist * dist), dist);\n" +
" float scalar = radian * factor / dist;\n" +
" vec2 new_coord = coord * scalar + vec2(0.5, 0.5);\n" +
" gl_FragColor = texture2D(u_Texture, new_coord);\n" +
"}\n";
于 2014-05-10T08:20:48.897 回答
2
于 2012-09-20T15:38:56.750 回答
1
也许更简单的解决方案是使用Android Media Effects API。但是,它仅适用于 API 14 及更高版本。
于 2012-11-21T05:10:55.543 回答