Java Color Alpha overwriteAlpha(Color c, float alpha)

Here you can find the source of overwriteAlpha(Color c, float alpha)

Description

Overwrites alpha value for given color.

License

Open Source License

Parameter

Parameter Description
c color to overwrite
alpha a new value of alpha

Return

a new Color object with a new specified alpha value

Declaration

public static Color overwriteAlpha(Color c, float alpha) 

Method Source Code

//package com.java2s;
/**//from   ww w  .j a  va2s  . co  m
 * License Agreement.
 *
 *  JBoss RichFaces - Ajax4jsf Component Library
 *
 * Copyright (C) 2007  Exadel, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

import java.awt.Color;

public class Main {
    /**
     * Overwrites alpha value for given color.
     *
     * @param c color to overwrite
     * @param alpha a new value of alpha
     * @return a new <code>Color</code> object with a new specified alpha value
     */
    public static Color overwriteAlpha(Color c, float alpha) {
        Color retVal = c;
        if (c != null) {
            retVal = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (alpha * 255 + 0.5));
        }
        return retVal;
    }
}

Related

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