graphics2D实现中心渐变

代码:

			int width = 1920;
            int height = 1080;
            Point2D center = new Point2D.Float(width / 2, height / 2);
            float radius = height / 2;
            float[] dist = {
    
     0.0f, 1.0f };
            //白色到透明色的渐变
            Color[] colors = {
    
    new Color(255,255,255), new Color(0,0,0, 0)};
            RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors);
            g2.setPaint(paint);
            Shape  shape = new Ellipse2D.Double(width / 2 - height / 2, 0, height, height);
            AlphaComposite ac2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.04f * i);
            g2.setComposite(ac2);
            g2.fill(shape);

效果图如下:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41858523/article/details/123040815
今日推荐