我正试图在Android中对BitMap图像实现鱼眼效果。是否有现有的库或算法可以提供帮助?
答案 0 :(得分:5)
我建议您使用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";
答案 1 :(得分:2)
答案 2 :(得分:1)
也许更简单的解决方案是使用Android Media Effects API。但它仅适用于API 14及更高版本。