Java Color Combine combineColors(int fgColor, int bgColor, int pctFg)

Here you can find the source of combineColors(int fgColor, int bgColor, int pctFg)

Description

combine Colors

License

Open Source License

Declaration

public static int combineColors(int fgColor, int bgColor, int pctFg) 

Method Source Code

//package com.java2s;

public class Main {

    public static int combineColors(int fgColor, int bgColor, int pctFg) {
        int resColor = 0;
        if (pctFg < 1) {
            resColor = bgColor;//from  www .ja  v  a 2  s.c o m
        } else if (pctFg == 100) {
            resColor = fgColor;
        } else {
            int pctBg = 100 - pctFg;
            resColor =
                    // Red
                    (((((((fgColor >> 16) & 0xff) * pctFg) + (((bgColor >> 16) & 0xff) * pctBg))) / 100) << 16) |
                    // Green
                            (((((((fgColor >> 8) & 0xff) * pctFg) + (((bgColor >> 8) & 0xff) * pctBg))) / 100) << 8)
                            |
                            // Blue
                            (((((fgColor & 0xff) * pctFg) + ((bgColor & 0xff) * pctBg))) / 100);
        }

        return resColor;
    }
}

Related

  1. combine(int r, int g, int b)
  2. combine(int r, int g, int b, int a)