Java RGB Color Convert To rgbBitfieldToString(int rgb)

Here you can find the source of rgbBitfieldToString(int rgb)

Description

Extracts the red green and blue portions as of a pixel and returns them as String.

License

Open Source License

Parameter

Parameter Description
rgb The color of the pixel as bitfield

Return

A String of the decimal representations of RED, GREEN and BLUE

Declaration

public static String rgbBitfieldToString(int rgb) 

Method Source Code

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

public class Main {
    /**//from   w ww. jav  a 2  s.  co  m
     * Extracts the red green and blue portions as of a pixel and returns them
     * as String.
     * 
     * @param rgb
     *            The color of the pixel as bitfield
     * @return A String of the decimal representations of RED, GREEN and BLUE
     */
    public static String rgbBitfieldToString(int rgb) {

        return getRed(rgb) + " " + getGreen(rgb) + " " + getBlue(rgb);
    }

    /**
     * Extracts the red portion from a given RGB color
     * 
     * @param rgb
     *            The color as bitfield
     * @return the decimal portion of red
     */
    public static int getRed(int rgb) {
        return (rgb >> 16) & 0xff;
    }

    /**
     * Extracts the green portion from a given RGB color
     * 
     * @param rgb
     *            The color as bitfield
     * @return the decimal portion of green
     */
    public static int getGreen(int rgb) {
        return (rgb >> 8) & 0xff;
    }

    /**
     * Extracts the blue portion from a given RGB color
     * 
     * @param rgb
     *            The color as bitfield
     * @return the decimal portion of blue
     */
    public static int getBlue(int rgb) {
        return (rgb) & 0xff;
    }
}

Related

  1. rgb8ToPixel(byte[] nrgb)
  2. rgb8ToRgbRBXG(byte[] rgb)
  3. rgbaToColor(int r, int g, int b, int a)
  4. rgbaToHex(String color)
  5. RGBAtoI(byte r, byte g, byte b, byte a)
  6. rgbToBgr(final byte[] pixels)
  7. RGBtoBGR(String color)
  8. rgbToBlackWhite(int pix, int threshold)
  9. rgbToColor(int r, int g, int b)