Java Color Blend blendAlpha(Color under, Color over)

Here you can find the source of blendAlpha(Color under, Color over)

Description

blend Alpha

License

Open Source License

Declaration

public static Color blendAlpha(Color under, Color over) 

Method Source Code


//package com.java2s;
/*/*from   w w w .j ava2 s .  c  o  m*/
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public 
 * License as published by the Free Software Foundation; either 
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this program; if not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
 * MA  02111-1307, USA.
 */

import java.awt.Color;

public class Main {
    public static Color blendAlpha(Color under, Color over) {
        float rgb1[] = new float[3];
        float rgb2[] = new float[3];

        under.getColorComponents(rgb1);
        over.getColorComponents(rgb2);
        int ualpha = under.getAlpha();
        int oalpha = over.getAlpha();
        float u = ualpha / 255f;
        float o = oalpha / 255f;
        u *= u * o;
        Color color = new Color(rgb1[0] * u + rgb2[0] * o, rgb1[1] * u + rgb2[1] * o, rgb1[2] * u + rgb2[2] * o);
        return color;
    }
}

Related

  1. blend(Color origin, Color over)
  2. blend(Color pColor, Color pOther)
  3. blend(double factor, Color color1, Color color2)
  4. blend(final Color color1, final Color color2, final double ratio)
  5. blend(final Color first, final Color second, final float alpha)
  6. blendcol(Color in, Color bl)
  7. blendColor(Color clOne, Color clTwo, double amount)
  8. blendColorKeepAlpha(Color source, Color dest)
  9. blendColors(Color color, Color color1, double d)