Java Color Convert To colorToHex(int integer)

Here you can find the source of colorToHex(int integer)

Description

Convert an integer representing a color scale to 2 hex digits.

License

Open Source License

Parameter

Parameter Description
integer a parameter

Return

A string of exactly 2 hexadecimal digits.

Declaration

private static String colorToHex(int integer) 

Method Source Code

//package com.java2s;

public class Main {
    /**// ww  w  .jav a 2  s .  c  o  m
     * Convert an integer representing a color scale to 2 hex digits.
     * 
     * @param integer
     * @return A string of exactly 2 hexadecimal digits.
     */
    private static String colorToHex(int integer) {
        if (integer > 255) {
            throw new IllegalArgumentException(
                    "Color value cannot be great than 255");
        }
        if (integer > 15) {
            return Integer.toHexString(integer);
        }

        return "0" + Integer.toHexString(integer);
    }
}

Related

  1. colorToFloat(int color)
  2. colorToHex(int color)
  3. colorToRGB(final int alpha, final int red, final int green, final int blue)
  4. colorToString(int color, boolean rgb)
  5. colorToStringHex(int red, int green, int blue)