The SetLinearGradient
method applies a linear gradient to a Bitmap
object. This gradient is defined by a start and end point, and a Gradient
object that specifies the color transitions.
The SetLinearGradient
method applies a linear gradient to a Bitmap
object. This gradient is defined by a start and end point, and a Gradient
object that specifies the color transitions.
To use the SetLinearGradient
method, you need to provide two Vector2
parameters that define the start and end points of the gradient, and a Gradient
object that contains the color stops and their respective positions.
This method is useful for creating smooth color transitions across a bitmap, which can be used for backgrounds, overlays, or any graphical element that requires a gradient effect.
// Create a new Bitmap instance Bitmap bitmap = new Bitmap(200, 200); // Define start and end points for the gradient Vector2 startPoint = new Vector2(0, 0); Vector2 endPoint = new Vector2(200, 200); // Create a Gradient object Gradient gradient = new Gradient(); gradient.AddColorStop(0.0f, Color.Red); gradient.AddColorStop(1.0f, Color.Blue); // Apply the linear gradient to the bitmap bitmap.SetLinearGradient(startPoint, endPoint, gradient);