android 光晕效果,【转】七、android图片特效处理之光晕效果
/*** 光晕效果*@parambmp*@paramx 光晕中心点在bmp中的x坐标*@paramy 光晕中心点在bmp中的y坐标*@paramr 光晕的半径*@return*/public Bitmap halo(Bitmap bmp, int x, int y, floatr){long start =System.currentTimeMillis();//高斯矩阵int[] gauss =
/*** 光晕效果
*@parambmp
*@paramx 光晕中心点在bmp中的x坐标
*@paramy 光晕中心点在bmp中的y坐标
*@paramr 光晕的半径
*@return
*/
public Bitmap halo(Bitmap bmp, int x, int y, floatr)
{long start =System.currentTimeMillis();//高斯矩阵
int[] gauss = new int[] { 1, 2, 1, 2, 4, 2, 1, 2, 1};int width =bmp.getWidth();int height =bmp.getHeight();
Bitmap bitmap=Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);int pixR = 0;int pixG = 0;int pixB = 0;int pixColor = 0;int newR = 0;int newG = 0;int newB = 0;int delta = 18; //值越小图片会越亮,越大则越暗
int idx = 0;int[] pixels = new int[width *height];
bmp.getPixels(pixels,0, width, 0, 0, width, height);for (int i = 1, length = height - 1; i < length; i++)
{for (int k = 1, len = width - 1; k < len; k++)
{
idx= 0;int distance = (int) (Math.pow(k - x, 2) + Math.pow(i - y, 2));//不是中心区域的点做模糊处理
if (distance > r *r)
{for (int m = -1; m <= 1; m++)
{for (int n = -1; n <= 1; n++)
{
pixColor= pixels[(i + m) * width + k +n];
pixR=Color.red(pixColor);
pixG=Color.green(pixColor);
pixB=Color.blue(pixColor);
newR= newR + (int) (pixR *gauss[idx]);
newG= newG + (int) (pixG *gauss[idx]);
newB= newB + (int) (pixB *gauss[idx]);
idx++;
}
}
newR/=delta;
newG/=delta;
newB/=delta;
newR= Math.min(255, Math.max(0, newR));
newG= Math.min(255, Math.max(0, newG));
newB= Math.min(255, Math.max(0, newB));
pixels[i* width + k] = Color.argb(255, newR, newG, newB);
newR= 0;
newG= 0;
newB= 0;
}
}
}
bitmap.setPixels(pixels,0, width, 0, 0, width, height);long end =System.currentTimeMillis();
Log.d("may", "used time="+(end -start));returnbitmap;
}
更多推荐
所有评论(0)