图片以圆心向四周渐变,逐渐透明 /** * 图片渐变透明 * @param sourceImg * @return */ public static Bitmap getTransparentImage(Bitmap sourceImg) { int width = sourceImg.getWidth(); int height = sourceImg.getHeight(); // double radius = Math.sqrt(Math.pow(width / 2.0, 2) + Math.pow(height / 2.0, 2));//设置半径 double radius = width / 2.0; int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()]; sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg .getWidth(), sourceImg.getHeight());// 获得图片的ARGB值 for (int i = 0; i < argb.length; i++) { int x = i % width; int y = i / width; double radiusI = Math.sqrt(Math.pow(Math.abs(x - (width / 2)), 2) + Math.pow(Math.abs(y - (height / 2)), 2));//该像素点与圆心距离 int number = 0; if (radiusI < radius) { //透明度 number = (int) (Math.abs(radius - radiusI) / radius * 255); } argb[i] = (number << 24) | (argb[i] & 0x00FFFFFF); } sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg .getHeight(), Bitmap.Config.ARGB_8888); return sourceImg; }
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交