Example usage for android.graphics Color rgb

List of usage examples for android.graphics Color rgb

Introduction

In this page you can find the example usage for android.graphics Color rgb.

Prototype

@ColorInt
public static int rgb(float red, float green, float blue) 

Source Link

Document

Return a color-int from red, green, blue float components in the range \([0..1]\).

Usage

From source file:Main.java

public static int darker(int c) {
    int r = Color.red(c);
    int b = Color.blue(c);
    int g = Color.green(c);

    return Color.rgb((int) (r * .7), (int) (g * .7), (int) (b * .7));
}

From source file:Main.java

/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
 *              0.0 will return {@code color2}.
 *///from  w w w  .ja v  a 2  s  .  com
public static int blendColors(int color1, int color2, float ratio) {
    final float inverseRatio = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRatio);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRatio);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRatio);
    return Color.rgb((int) r, (int) g, (int) b);
}

From source file:Main.java

public static Integer getColorFromRgb(String rgb) {
    String[] rgbArray = rgb.split("\\s+");
    return Color.rgb(Integer.valueOf(rgbArray[0]), Integer.valueOf(rgbArray[1]), Integer.valueOf(rgbArray[2]));
}

From source file:Main.java

public static Integer getColorFromRgb(String rgb) {
    String[] rgbArray = rgb.split("\\s+");
    int color = Color.rgb(Integer.valueOf(rgbArray[0]), Integer.valueOf(rgbArray[1]),
            Integer.valueOf(rgbArray[2]));
    return color;
}

From source file:Main.java

public static Bitmap applyFilter(Bitmap bmpOriginal) {
    int width = bmpOriginal.getWidth();
    int height = bmpOriginal.getHeight();

    int core[][] = { { 1, 1, 1 }, { 1, 2, 1 }, { 1, 1, 1 } };

    int[] result = new int[height * width];
    int[][] pixels2D = new int[height][width];
    for (int i = 0; i < height; i++) {
        bmpOriginal.getPixels(pixels2D[i], 0, width, 0, i, width, 1);
    }//from w w  w .  j a  va2  s.  c o  m

    int count = 0;
    int R, G, B;
    for (int i = 0; i < height; i++)
        for (int j = 0; j < width; j++) {
            R = dotProduct(i, j, 0, pixels2D, core) / 10 + 20;
            G = dotProduct(i, j, 1, pixels2D, core) / 10 + 20;
            B = dotProduct(i, j, 2, pixels2D, core) / 10 + 20;

            result[count] = Color.rgb(R, G, B);
            count++;
        }

    Bitmap bmpFiltered = Bitmap.createBitmap(result, 0, width, width, height, Bitmap.Config.RGB_565);
    return bmpFiltered;
}

From source file:Main.java

/**
 * Heuristic method to determine if the image looks empty. Works by taking a horisontal row of pixels from he
 * middle, and looks if they're all pure white.
 *
 * @param refinedImage A pre-processed image of the evolution cost. (should be pre-refined to replace all non
 *                     text colors with pure white)
 * @return true if the image is likely only white
 */// ww  w . j  a va2s . c o  m
private static boolean isOnlyWhite(Bitmap refinedImage) {
    int[] pixelArray = new int[refinedImage.getWidth()];

    //below code takes one line of pixels in the middle of the pixture from left to right
    refinedImage.getPixels(pixelArray, 0, refinedImage.getWidth(), 0, refinedImage.getHeight() / 2,
            refinedImage.getWidth(), 1);

    for (int pixel : pixelArray) {
        if (pixel != Color.rgb(255, 255, 255)) { // if pixel is not white
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static int colorBurn(int RGBValues) {
    int red = RGBValues >> 16 & 0xFF;
    int green = RGBValues >> 8 & 0xFF;
    int blue = RGBValues & 0xFF;
    red = (int) Math.floor(red * (1 - 0.1));
    green = (int) Math.floor(green * (1 - 0.1));
    blue = (int) Math.floor(blue * (1 - 0.1));
    return Color.rgb(red, green, blue);
}

From source file:Main.java

public static int getColor(int red, int green, int blue) {
    return Color.rgb(red, green, blue);
}

From source file:Main.java

private static int parseShortColorCode(String colorString) {
    String rgb = colorString.substring(1);
    int r = Integer.parseInt(rgb.substring(0, 1) + rgb.substring(0, 1), 16);
    int g = Integer.parseInt(rgb.substring(1, 2) + rgb.substring(1, 2), 16);
    int b = Integer.parseInt(rgb.substring(2, 3) + rgb.substring(2, 3), 16);
    return Color.rgb(r, g, b);
}

From source file:Main.java

public static int lighten(int c, float amount) {
    int r = Color.red(c);
    int b = Color.blue(c);
    int g = Color.green(c);

    int red = (int) ((r * (1 - amount) / 255 + amount) * 255);
    int green = (int) ((g * (1 - amount) / 255 + amount) * 255);
    int blue = (int) ((b * (1 - amount) / 255 + amount) * 255);

    return (Color.rgb(red, green, blue));
}