How to implement oval GradientPaint?

前端 未结 2 1544
天命终不由人
天命终不由人 2020-12-10 19:49

We know that there are a class named RadialGradientPaint in Java and we can use it to have a gradient painting for circle.

But I want to have an oval (e

2条回答
  •  攒了一身酷
    2020-12-10 20:29

    RadialGradientPaint provides two ways to paint itself as an ellipse instead of a circle:

    1. Upon construction, you can specify a transform for the gradient. For example, if you provide the following transform: AffineTransform.getScaleInstance(0.5, 1), your gradient will be an upright oval (the x dimension will be half that of the y dimension).

    2. Or, you can use the constructor that requires a Rectangle2D be provided. An appropriate transform will be created to make the gradient ellipse bounds match that of the provided rectangle. I found the class documentation helpful: RadialGradientPaint API. In particular, see the documentation for this constructor.

提交回复
热议问题