Java Color Alpha premultiplyAlpha(Color fgColor, Color bgColor)

Here you can find the source of premultiplyAlpha(Color fgColor, Color bgColor)

Description

premultiply Alpha

License

Open Source License

Declaration

public static final Color premultiplyAlpha(Color fgColor, Color bgColor) 

Method Source Code


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

import java.awt.Color;

public class Main {
    public static final Color premultiplyAlpha(Color fgColor, Color bgColor) {
        int r, g, b;
        r = fgColor.getRed() * fgColor.getAlpha() + bgColor.getRed() * (255 - fgColor.getAlpha());
        g = fgColor.getGreen() * fgColor.getAlpha() + bgColor.getGreen() * (255 - fgColor.getAlpha());
        b = fgColor.getBlue() * fgColor.getAlpha() + bgColor.getBlue() * (255 - fgColor.getAlpha());
        Color result = new Color(r / 255, g / 255, b / 255);
        return result;
    }/*from   www . ja  v  a2s  .c  o  m*/
}

Related

  1. changeColorAlpha(@Nonnull Color color, int newAlpha)
  2. deriveWithAlpha(Color color, int alpha)
  3. newColourWithAlpha(Color color, double alpha)
  4. noAlpha(final Color col)
  5. overwriteAlpha(Color c, float alpha)
  6. setColorAlpha(Color c, int alpha)
  7. setColorAlpha(Color color, int alpha)
  8. transparent(final Color color, final int alpha)
  9. transparentColor(Color color, int alpha)