Java Code Examples for android.graphics.Color.red()

The following are Jave code examples for showing how to use red() of the android.graphics.Color class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: CustomAndroidOneSheeld   File: ColorDetectionShield.java   View Source Code Vote up 6 votes
int getColorInRange(int color, ColorPalette palette) {
    int i = 0;
    if (palette.isGrayscale) {
        i = palette.getNumberOfBits();
        int grayscale = (Color.red(color) + Color.green(color) + Color
                .blue(color)) / 3;
        color = Color.rgb(grayscale, grayscale, grayscale);
    } else
        i = palette.getNumberOfBits() / 3;

    int newR = (int) Math
            .round(((Color.red(color) >>> (8 - i)) * (255 / (Math.pow(2, i) - 1))));
    int newG = (int) Math
            .round(((Color.green(color) >>> (8 - i)) * (255 / (Math.pow(2, i) - 1))));
    int newB = (int) Math
            .round(((Color.blue(color) >>> (8 - i)) * (255 / (Math.pow(2, i) - 1))));
    return Color.rgb(newR, newG, newB);
}
 
Example 2
Project: rgb2hexconverter   File: MainActivity.java   View Source Code Vote up 5 votes
private int[] inColorToRGB(int color) {
    int[] rgb = new int[3];
    rgb[0] = Color.red(color);
    rgb[1] = Color.green(color);
    rgb[2] = Color.blue(color);
    return rgb;
}
 
Example 3
Project: exciting-app   File: AnimatedGifEncoder.java   View Source Code Vote up 5 votes
protected void getImagePixels() {
    int w = this.image.getWidth();
    int h = this.image.getHeight();
    Bitmap localBitmap1 = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas localCanvas = new Canvas(localBitmap1);
    localCanvas.save();
    Paint localPaint = new Paint();
    localCanvas.drawBitmap(image, postX, postY, localPaint);
    localCanvas.restore();

    this.pixels = new byte[w * h * 3];
    int[] arrayOfInt = new int[w * h];
    int k = 0;
    int l = 0;
    int i1 = w;
    localBitmap1.getPixels(arrayOfInt, 0, w, k, l, i1, h);
    int localObject = 0;
    while (true) {

        if (localObject >= arrayOfInt.length)
            return;
        pixels[localObject * 3] = (byte) Color.blue(arrayOfInt[localObject]);
        pixels[localObject * 3 + 1] = (byte) Color.green(arrayOfInt[localObject]);
        pixels[localObject * 3 + 2] = (byte) Color.red(arrayOfInt[localObject]);
        ++localObject;
    }
}
 
Example 4
Project: AndroidDigIn   File: Utils.java   View Source Code Vote up 5 votes
/**
 * 从颜色得到另一个对比度高的颜色,其实就是给出黑白两种色,
 * 不过传入的颜色如果较暗,那就是白色,如果较亮那就是黑色
 * @param color
 * @return
 */
public static int getComplimentColor(@ColorInt int color) {
    // get existing colors
    int alpha = Color.alpha(color);
    int red = Color.red(color);
    int blue = Color.blue(color);
    int green = Color.green(color);

    // find compliments
    red = (~red) & 0xff;
    blue = (~blue) & 0xff;
    green = (~green) & 0xff;

    return Color.argb(alpha, red, green, blue);
}
 
Example 5
Project: GitHub   File: SlidingTabStrip.java   View Source Code Vote up 5 votes
/**
 * 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}.
 */
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}
 
Example 6
Project: qmui   File: QMUICollapsingTextHelper.java   View Source Code Vote up 5 votes
/**
 * Blend {@code color1} and {@code color2} using the given ratio.
 *
 * @param ratio of which to blend. 0.0 will return {@code color1}, 0.5 will give an even blend,
 *              1.0 will return {@code color2}.
 */
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRatio = 1f - ratio;
    float a = (Color.alpha(color1) * inverseRatio) + (Color.alpha(color2) * ratio);
    float r = (Color.red(color1) * inverseRatio) + (Color.red(color2) * ratio);
    float g = (Color.green(color1) * inverseRatio) + (Color.green(color2) * ratio);
    float b = (Color.blue(color1) * inverseRatio) + (Color.blue(color2) * ratio);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}
 
Example 7
Project: PlusGram   File: AndroidUtilities.java   View Source Code Vote up 5 votes
public static int setDarkColor(int color, int factor) {
    int alpha = Color.alpha(color);
    int red = Color.red(color) - factor;
    int green = Color.green(color) - factor;
    int blue = Color.blue(color) - factor;
    if (factor < 0) {
        red = (red > 0xff) ? 0xff : red;
        green = (green > 0xff) ? 0xff : green;
        blue = (blue > 0xff) ? 0xff : blue;
        if (red == 0xff && green == 0xff && blue == 0xff) {
            red = factor;
            green = factor;
            blue = factor;
        }
    }
    if (factor > 0) {
        red = (red < 0) ? 0 : red;
        green = (green < 0) ? 0 : green;
        blue = (blue < 0) ? 0 : blue;
        if (red == 0 && green == 0 && blue == 0) {
            red = factor;
            green = factor;
            blue = factor;
        }
    }
    //return Color.argb(0xff, red, green, blue);
    return Color.argb(alpha, red, green, blue);
}
 
Example 8
Project: PlusGram   File: ColorSelectorDialog.java   View Source Code Vote up 5 votes
private int adjustAlpha(int color, boolean b) {
    int alpha = (b) ? Color.alpha(color) : 0xff;
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}
 
Example 9
Project: Trivia-Knowledge   File: SlidingTabStrip.java   View Source Code Vote up 5 votes
/**
 * 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}.
 */
private static int blendColors(int color1, int color2, float ratio) {
    final float inverseRation = 1f - ratio;
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
    return Color.rgb((int) r, (int) g, (int) b);
}
 
Example 10
Project: XinFramework   File: ColorUtils.java   View Source Code Vote up 5 votes
public static int interpolateColor(int colorFrom, int colorTo, int posFrom, int posTo) {
    float delta = posTo - posFrom;
    int red = (int) ((Color.red(colorFrom) - Color.red(colorTo)) * delta / posTo + Color.red(colorTo));
    int green = (int) ((Color.green(colorFrom) - Color.green(colorTo)) * delta / posTo + Color.green(colorTo));
    int blue = (int) ((Color.blue(colorFrom) - Color.blue(colorTo)) * delta / posTo) + Color.blue(colorTo);
    return Color.argb(255, red, green, blue);
}
 
Example 11
Project: MetadataEditor   File: ColorUtil.java   View Source Code Vote up 5 votes
@ColorInt
public static int invertColor(@ColorInt int color) {
    final int r = 255 - Color.red(color);
    final int g = 255 - Color.green(color);
    final int b = 255 - Color.blue(color);
    return Color.argb(Color.alpha(color), r, g, b);
}
 
Example 12
Project: GitHub   File: CircleView.java   View Source Code Vote up 5 votes
@ColorInt private static int translucentColor(int color) {
    final float factor = 0.7f;
    int alpha = Math.round(Color.alpha(color) * factor);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}
 
Example 13
Project: simple-share-android   File: ColorUtils.java   View Source Code Vote up 5 votes
/**
 * Returns the luminance of a color.
 *
 * Formula defined here: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
 */
private static double calculateLuminance(int color) {
    double red = Color.red(color) / 255d;
    red = red < 0.03928 ? red / 12.92 : Math.pow((red + 0.055) / 1.055, 2.4);

    double green = Color.green(color) / 255d;
    green = green < 0.03928 ? green / 12.92 : Math.pow((green + 0.055) / 1.055, 2.4);

    double blue = Color.blue(color) / 255d;
    blue = blue < 0.03928 ? blue / 12.92 : Math.pow((blue + 0.055) / 1.055, 2.4);

    return (0.2126 * red) + (0.7152 * green) + (0.0722 * blue);
}
 
Example 14
Project: ceji_android   File: CommonUtils.java   View Source Code Vote up 4 votes
public static int getBlackWhiteColor(int color) {
    double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
    if (darkness >= 0.5) {
        return Color.WHITE;
    } else return Color.BLACK;
}
 
Example 15
Project: homeassist-builder   File: CallServiceRequest.java   View Source Code Vote up 4 votes
public CallServiceRequest setRGBColor(int rgbColor) {
    this.rgbColor = new Integer[]{Color.red(rgbColor), Color.green(rgbColor), Color.blue(rgbColor)};
    return this;
}
 
Example 16
Project: XFrame   File: XBitmapUtils.java   View Source Code Vote up 4 votes
/**
 * 浮雕效果处理
 *
 * @param bitmap 原图
 * @return 浮雕效果处理后的图片
 */
public static Bitmap emboss(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height,
            Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;

    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    int pos = 0;
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            pos = i * width + k;
            pixColor = pixels[pos];

            pixR = Color.red(pixColor);
            pixG = Color.green(pixColor);
            pixB = Color.blue(pixColor);

            pixColor = pixels[pos + 1];
            newR = Color.red(pixColor) - pixR + 127;
            newG = Color.green(pixColor) - pixG + 127;
            newB = Color.blue(pixColor) - pixB + 127;

            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));

            pixels[pos] = Color.argb(255, newR, newG, newB);
        }
    }

    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}
 
Example 17
Project: XFrame   File: XBitmapUtils.java   View Source Code Vote up 4 votes
/**
 * 柔化效果处理
 *
 * @param bitmap 原图
 * @return 柔化效果处理后的图片
 */
public static Bitmap soften(Bitmap bitmap) {
    // 高斯矩阵
    int[] gauss = new int[]{1, 2, 1, 2, 4, 2, 1, 2, 1};

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height,
            Config.RGB_565);

    int pixR = 0;
    int pixG = 0;
    int pixB = 0;

    int pixColor = 0;

    int newR = 0;
    int newG = 0;
    int newB = 0;

    int delta = 16; // 值越小图片会越亮,越大则越暗

    int idx = 0;
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    for (int i = 1, length = height - 1; i < length; i++) {
        for (int k = 1, len = width - 1; k < len; k++) {
            idx = 0;
            for (int m = -1; m <= 1; m++) {
                for (int n = -1; n <= 1; n++) {
                    pixColor = pixels[(i + m) * width + k + n];
                    pixR = Color.red(pixColor);
                    pixG = Color.green(pixColor);
                    pixB = Color.blue(pixColor);

                    newR = newR + (int) (pixR * gauss[idx]);
                    newG = newG + (int) (pixG * gauss[idx]);
                    newB = newB + (int) (pixB * gauss[idx]);
                    idx++;
                }
            }

            newR /= delta;
            newG /= delta;
            newB /= delta;

            newR = Math.min(255, Math.max(0, newR));
            newG = Math.min(255, Math.max(0, newG));
            newB = Math.min(255, Math.max(0, newB));

            pixels[i * width + k] = Color.argb(255, newR, newG, newB);

            newR = 0;
            newG = 0;
            newB = 0;
        }
    }

    newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return newBitmap;
}
 
Example 18
Project: Samantha   File: ColorUtils.java   View Source Code Vote up 4 votes
public static boolean isColorDark(@ColorInt int color) {
    double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
    return darkness >= 0.5;
}
 
Example 19
Project: SSTVEncoder2   File: YuvConverter.java   View Source Code Vote up 4 votes
static int convertToY(int color) {
    double R = Color.red(color);
    double G = Color.green(color);
    double B = Color.blue(color);
    return clamp(16.0 + (.003906 * ((65.738 * R) + (129.057 * G) + (25.064 * B))));
}
 
Example 20
Project: iosched-reader   File: UIUtils.java   View Source Code Vote up 2 votes
/**
 * Calculate whether a color is light or dark, based on a commonly known
 * brightness formula.
 *
 * @see {@literal http://en.wikipedia.org/wiki/HSV_color_space%23Lightness}
 */
public static boolean isColorDark(int color) {
    return ((30 * Color.red(color) +
            59 * Color.green(color) +
            11 * Color.blue(color)) / 100) <= BRIGHTNESS_THRESHOLD;
}