Java BufferedImage Operation verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors)

Here you can find the source of verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors)

Description

vertical Gradient

License

Open Source License

Declaration

public static void verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;

import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Point;

import java.awt.geom.Point2D;

import java.awt.image.BufferedImage;

public class Main {
    public static void verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors) {
        int miniHeight = image.getHeight() / (colors.length - 1);
        for (int i = 1; i < colors.length; i++) {
            Point start = new Point(0, (i - 1) * miniHeight);
            Point end = new Point(0, i * miniHeight);
            gradientPaint(g2d, start, colors[i - 1], end, colors[i], start.x, start.y, image.getWidth(), end.y);
        }//from w w  w  .  jav  a 2  s.  com
    }

    public static void gradientPaint(Graphics2D g2d, Point2D startPosition, Color startColor, Point2D endPosition,
            Color endColor, int sx, int sy, int ex, int ey) {
        GradientPaint gradient = new GradientPaint(startPosition, startColor, endPosition, endColor, true);
        g2d.setPaint(gradient);
        g2d.fillRect(sx, sy, ex, ey);
    }
}

Related

  1. tilt(BufferedImage image, double angle)
  2. tintImage(BufferedImage src, Color color, float tintOpacity)
  3. unweaveFrom(BufferedImage bufferedImage)
  4. updateImageSpecifications( BufferedImage bufferedImage)
  5. validateSelectionRectangle(BufferedImage image, Rectangle selection)
  6. waterMarkImage(final BufferedImage image, final String text)
  7. weaveInto(BufferedImage bufferedImage, String message)