Java Color Alpha noAlpha(final Color col)

Here you can find the source of noAlpha(final Color col)

Description

Removes the transparency of the given color.

License

Open Source License

Parameter

Parameter Description
col The color.

Return

The same color without transparency.

Declaration

public static Color noAlpha(final Color col) 

Method Source Code

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

import java.awt.Color;

public class Main {
    /**// w w w. j a  v a  2 s .c  o m
     * Removes the transparency of the given color.
     * 
     * @param col The color.
     * @return The same color without transparency.
     */
    public static Color noAlpha(final Color col) {
        return noAlpha(col, null);
    }

    /**
     * Removes the transparency of the given color.
     * 
     * @param col The color.
     * @param alpha An optional array with a length of at least one that is used
     *          to store the previous alpha value of the color in slot 0.
     * @return The same color without transparency.
     */
    public static Color noAlpha(final Color col, final float[] alpha) {
        final float[] comp = col.getRGBComponents(null);
        if (alpha != null) {
            alpha[0] = comp[3];
        }
        if (comp[3] == 1)
            return col;
        return new Color(comp[0], comp[1], comp[2]);
    }
}

Related

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