public final class LinearGradient

  1. Object
  2. Gradient
  3. LinearGradient

ImplementsPaint

Multi-stop linear gradient at an arbitrary angle. Mirrors CSS linear-gradient(<angle>, <stops>). Angle is in CSS degrees: 0 points up (toward the top edge), 90 right, 180 down, 270 left.

Constructors

public LinearGradient(float angleDegrees, int[] colors, float[] positions)Creates a linear gradient at the given angle with the given stops.

Methods

public byte getKind()Returns one of KIND_LINEAR, KIND_RADIAL, KIND_CONIC.
public float getAngleDegrees()
public LinearGradient setAngleDegrees(float angleDegrees)
public void computeEndpoints(int width, int height, float[] out)Computes the endpoints of the gradient line for a rectangle of the given width / height (rect origin at (0,0)).
public void computeShaderEndpoints(int width, int height, float[] out)Computes shader-ready endpoints for native APIs like Android’s LinearGradient and Java2D’s LinearGradientPaint.
public float[] getNormalizedPositions()Returns stop positions rescaled to [0, 1] within the [first_stop, last_stop] range of the original positions.
public int sampleArgb(int px, int py, int width, int height)Software-rasterizer hook used by the default port implementation when no native gradient shader is available.
public LinearGradient copy()Returns a defensive deep copy.

Inherited fields

Inherited methods

Constructor details

LinearGradient

public LinearGradient(float angleDegrees, int[] colors, float[] positions)
Creates a linear gradient at the given angle with the given stops.

Method details

getKind

public byte getKind()
Returns one of KIND_LINEAR, KIND_RADIAL, KIND_CONIC.

getAngleDegrees

public float getAngleDegrees()

setAngleDegrees

public LinearGradient setAngleDegrees(float angleDegrees)

computeEndpoints

public void computeEndpoints(int width, int height, float[] out)
Computes the endpoints of the gradient line for a rectangle of the given width / height (rect origin at (0,0)). Output is x0,y0,x1,y1. These endpoints span the full bounding box; stop positions are interpreted relative to them.

computeShaderEndpoints

public void computeShaderEndpoints(int width, int height, float[] out)

Computes shader-ready endpoints for native APIs like Android’s LinearGradient and Java2D’s LinearGradientPaint. For NO_CYCLE this is the same as computeEndpoints. For REPEAT / REFLECT it clips the endpoint range to span exactly one stop-list period (from getPositions()[0] to getPositions()[N-1] of the original line) so the native shader’s tile mode wraps the period across the rest of the bounding box - matching the CSS repeating-linear-gradient semantic.

Use getNormalizedPositions() for the matching stop array when using these endpoints with REPEAT/REFLECT.

getNormalizedPositions

public float[] getNormalizedPositions()
Returns stop positions rescaled to [0, 1] within the [first_stop, last_stop] range of the original positions. For NO_CYCLE this is the same as getPositions(); for REPEAT/REFLECT it is the array to pass alongside computeShaderEndpoints.

sampleArgb

public int sampleArgb(int px, int py, int width, int height)
Software-rasterizer hook used by the default port implementation when no native gradient shader is available. Samples an ARGB color for the pixel at (px, py) within a rectangle of the given width / height. Ports overriding fillGradient directly do not call this.

copy

public LinearGradient copy()
Returns a defensive deep copy. Implemented by each concrete subclass so async-paint queues can capture an immutable snapshot.