Java Color Blend blend(Color c0, Color c1)

Here you can find the source of blend(Color c0, Color c1)

Description

blend

License

Open Source License

Declaration

public static Color blend(Color c0, Color c1) 

Method Source Code


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

import java.awt.*;

public class Main {
    public static Color blend(Color c0, Color c1) {
        double totalAlpha = c0.getAlpha() + c1.getAlpha();
        double weight0 = c0.getAlpha() / totalAlpha;
        double weight1 = c1.getAlpha() / totalAlpha;

        double r = weight0 * c0.getRed() + weight1 * c1.getRed();
        double g = weight0 * c0.getGreen() + weight1 * c1.getGreen();
        double b = weight0 * c0.getBlue() + weight1 * c1.getBlue();
        double a = Math.max(c0.getAlpha(), c1.getAlpha());

        return new Color((int) r, (int) g, (int) b, (int) a);
    }//w ww . j  a v  a  2 s .  c o  m
}

Related

  1. alphaBlend(Color o, int a)
  2. alphaBlend(final Color src, final Color dst)
  3. blend(Color a, Color b)
  4. blend(Color a, Color b, double val)
  5. blend(Color c1, Color c2)
  6. blend(Color c1, Color c2)
  7. blend(Color c1, Color c2, double v)
  8. blend(Color cFrom, Color cTo, float factor)