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

The following examples show how to use android.graphics.Color#red() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OC_PlayZoneTrace.java    From GLEXP-Team-onebillion with Apache License 2.0 6 votes vote down vote up
public boolean pixelsLeft(float threshold)
{
    int w = bitmapContext.getWidth();
    int h = bitmapContext.getHeight();
    int pixelThreshold = (int)(fillablePixelCount * threshold);
    int tot = 0;
    int pixels[] = new int[w];
    for(int i = 0;i < h;i++)
    {
        bitmapContext.getPixels(pixels, 0, w, 0, i, w, 1);
        for(int j = 0;j < w;j++)
        {
            int px = pixels[j];
            if (Color.red(px) > 25)
                tot++;
            if(tot > pixelThreshold)
                return false;
        }
    }
    return true;
}
 
Example 2
Source File: ThemeEditorView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void setColor(int color) {
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    int a = Color.alpha(color);
    if (!ignoreTextChange) {
        ignoreTextChange = true;
        colorEditText[0].setText("" + red);
        colorEditText[1].setText("" + green);
        colorEditText[2].setText("" + blue);
        colorEditText[3].setText("" + a);
        for (int b = 0; b < 4; b++) {
            colorEditText[b].setSelection(colorEditText[b].length());
        }
        ignoreTextChange = false;
    }
    alphaGradient = null;
    colorGradient = null;
    alpha = a / 255.0f;
    Color.colorToHSV(color, colorHSV);
    invalidate();
}
 
Example 3
Source File: SlidingTabStrip.java    From MaterialRohling with MIT License 5 votes vote down vote up
/**
 * 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 4
Source File: PaletteActivity.java    From MaterialDesignDemo with MIT License 5 votes vote down vote up
private int generateTransparentColor(float percent, int rgb) {
    int red = Color.red(rgb);
    int green = Color.green(rgb);
    int blue = Color.blue(rgb);
    int alpha = Color.alpha(rgb);
    alpha = (int) (alpha * percent);
    return Color.argb(alpha, red, green, blue);
}
 
Example 5
Source File: FloatingActionsMenu.java    From android-chat-ui with Apache License 2.0 5 votes vote down vote up
static int darkenColor(double factor, int color) {
  int a = Color.alpha( color );
  int r = Color.red( color );
  int g = Color.green( color );
  int b = Color.blue( color );

  return Color.argb( a,
          Math.max( (int)(r * factor), 0 ),
          Math.max( (int)(g * factor), 0 ),
          Math.max( (int)(b * factor), 0 ) );
}
 
Example 6
Source File: ColorUtil.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Taken from CollapsingToolbarLayout's CollapsingTextHelper class.
 */
public static int blendColors(int color1, int color2, @FloatRange(from = 0.0, to = 1.0) 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
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static int getOffsetColor(int color1, int color2, float offset, float alpha) {
    int rF = Color.red(color2);
    int gF = Color.green(color2);
    int bF = Color.blue(color2);
    int aF = Color.alpha(color2);
    int rS = Color.red(color1);
    int gS = Color.green(color1);
    int bS = Color.blue(color1);
    int aS = Color.alpha(color1);
    return Color.argb((int) ((aS + (aF - aS) * offset) * alpha), (int) (rS + (rF - rS) * offset), (int) (gS + (gF - gS) * offset), (int) (bS + (bF - bS) * offset));
}
 
Example 8
Source File: Utils.java    From DialogSheet with MIT License 5 votes vote down vote up
@ColorInt
static int adjustAlpha(@ColorInt int color, float factor) {
    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 9
Source File: ColorEvaluator.java    From Storm with Apache License 2.0 5 votes vote down vote up
public static ColorHolder fromARGB(int color) {
    return new ColorHolder(
            Color.alpha(color),
            Color.red(color),
            Color.green(color),
            Color.blue(color)
    );
}
 
Example 10
Source File: Utils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public 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 11
Source File: ColorUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Calculates the contrast between the given color and white, using the algorithm provided by
 * the WCAG v2 in http://www.w3.org/TR/WCAG20/#contrast-ratiodef.
 */
private static float getContrastForColor(int color) {
    float bgR = Color.red(color) / 255f;
    float bgG = Color.green(color) / 255f;
    float bgB = Color.blue(color) / 255f;
    bgR = (bgR < 0.03928f) ? bgR / 12.92f : (float) Math.pow((bgR + 0.055f) / 1.055f, 2.4f);
    bgG = (bgG < 0.03928f) ? bgG / 12.92f : (float) Math.pow((bgG + 0.055f) / 1.055f, 2.4f);
    bgB = (bgB < 0.03928f) ? bgB / 12.92f : (float) Math.pow((bgB + 0.055f) / 1.055f, 2.4f);
    float bgL = 0.2126f * bgR + 0.7152f * bgG + 0.0722f * bgB;
    return Math.abs((1.05f) / (bgL + 0.05f));
}
 
Example 12
Source File: CompassView.java    From android with Apache License 2.0 5 votes vote down vote up
private static int swapColor(int c1, int c2, float p) {
    float i = 1 - p;
    int r = (int) (Color.red(c1) * i + Color.red(c2) * p);
    int g = (int) (Color.green(c1) * i + Color.green(c2) * p);
    int b = (int) (Color.blue(c1) * i + Color.blue(c2) * p);
    return Color.argb(0xFF, r, g, b);
}
 
Example 13
Source File: CheckBox.java    From fingerpoetry-android with Apache License 2.0 5 votes vote down vote up
private int rippleColor(int color) {
    int alpha = Math.round(Color.alpha(color) * 0.3f);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}
 
Example 14
Source File: SlidingTabStrip.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
/**
 * 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 15
Source File: BitmapUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 浮雕效果处理
 *
 * @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 16
Source File: XBitmapUtils.java    From XFrame with Apache License 2.0 4 votes vote down vote up
/**
 * 模糊效果处理
 * @return 模糊效果处理后的图片
 */
public Bitmap blur(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

    int pixColor = 0;

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

    int newColor = 0;

    int[][] colors = new int[9][3];
    for (int i = 1, length = width - 1; i < length; i++) {
        for (int k = 1, len = height - 1; k < len; k++) {
            for (int m = 0; m < 9; m++) {
                int s = 0;
                int p = 0;
                switch (m) {
                    case 0:
                        s = i - 1;
                        p = k - 1;
                        break;
                    case 1:
                        s = i;
                        p = k - 1;
                        break;
                    case 2:
                        s = i + 1;
                        p = k - 1;
                        break;
                    case 3:
                        s = i + 1;
                        p = k;
                        break;
                    case 4:
                        s = i + 1;
                        p = k + 1;
                        break;
                    case 5:
                        s = i;
                        p = k + 1;
                        break;
                    case 6:
                        s = i - 1;
                        p = k + 1;
                        break;
                    case 7:
                        s = i - 1;
                        p = k;
                        break;
                    case 8:
                        s = i;
                        p = k;
                }
                pixColor = bitmap.getPixel(s, p);
                colors[m][0] = Color.red(pixColor);
                colors[m][1] = Color.green(pixColor);
                colors[m][2] = Color.blue(pixColor);
            }

            for (int m = 0; m < 9; m++) {
                newR += colors[m][0];
                newG += colors[m][1];
                newB += colors[m][2];
            }

            newR = (int) (newR / 9F);
            newG = (int) (newG / 9F);
            newB = (int) (newB / 9F);

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

            newColor = Color.argb(255, newR, newG, newB);
            newBitmap.setPixel(i, k, newColor);

            newR = 0;
            newG = 0;
            newB = 0;
        }
    }
    return newBitmap;
}
 
Example 17
Source File: ImageFilterUtils.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
/**
 * 底片效果处理
 * @param bitmap 待操作源图片
 * @return 底片效果处理后的图片
 */
public static Bitmap film(final Bitmap bitmap) {
    if (bitmap == null) return null;
    try {
        // ARGB 的最大值
        final int MAX_VALUE = 255;
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();

        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);

                newR = MAX_VALUE - pixR;
                newG = MAX_VALUE - pixG;
                newB = MAX_VALUE - pixB;

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

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

        Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        newBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        return newBitmap;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "film");
    }
    return null;
}
 
Example 18
Source File: ParticleSystem.java    From EZFilter with MIT License 4 votes vote down vote up
/**
 * Add one particle to the vertexArray (native memory)
 *
 * @param startTime    - particle born time.
 * @param duration     - particle duration time.
 * @param fromSize     - particle from size.
 * @param toSize       - particle to size.
 * @param fromAngle    - particle from angle.
 * @param toAngle      - particle to angle.
 * @param position     - particle position.
 * @param direction    - particle direction.
 * @param fromColor    - particle from color.
 * @param toColor      - particle to color.
 * @param textureIndex - particle texture index.
 */
public void addParticle(float startTime,
                        float duration,
                        float fromSize,
                        float toSize,
                        float fromAngle,
                        float toAngle,
                        Geometry.Point position,
                        Geometry.Vector direction,
                        int fromColor,
                        int toColor,
                        int textureIndex) {
    final int particleOffset = mNextParticle * TOTAL_COMPONENT_COUNT;
    int currentOffset = particleOffset;
    mNextParticle++;

    if (mCurrentParticleCount < mMaxParticleCount) {
        mCurrentParticleCount++;
    }
    if (mNextParticle == mMaxParticleCount) {
        mNextParticle = 0;
    }

    mParticles[currentOffset++] = startTime;
    mParticles[currentOffset++] = duration;
    mParticles[currentOffset++] = fromSize;
    mParticles[currentOffset++] = toSize;
    mParticles[currentOffset++] = fromAngle;
    mParticles[currentOffset++] = toAngle;

    mParticles[currentOffset++] = position.x;
    mParticles[currentOffset++] = position.y;
    mParticles[currentOffset++] = position.z;

    mParticles[currentOffset++] = direction.x;
    mParticles[currentOffset++] = direction.y;
    mParticles[currentOffset++] = direction.z;

    mParticles[currentOffset++] = Color.red(fromColor) / 255f;
    mParticles[currentOffset++] = Color.green(fromColor) / 255f;
    mParticles[currentOffset++] = Color.blue(fromColor) / 255f;
    mParticles[currentOffset++] = Color.alpha(fromColor) / 255f;

    mParticles[currentOffset++] = Color.red(toColor) / 255f;
    mParticles[currentOffset++] = Color.green(toColor) / 255f;
    mParticles[currentOffset++] = Color.blue(toColor) / 255f;
    mParticles[currentOffset++] = Color.alpha(toColor) / 255f;

    mParticles[currentOffset++] = textureIndex;

    // Refresh only requested part of the native memory (one particle at a time)
    mVertexArray.updateBuffer(mParticles, particleOffset, TOTAL_COMPONENT_COUNT);
}
 
Example 19
Source File: BitmapProcessing.java    From Effects-Pro with MIT License 4 votes vote down vote up
public static final Bitmap sketch(Bitmap src) {
	int type = 6;
	int threshold = 130;
	
	int width = src.getWidth();
	int height = src.getHeight();
	Bitmap result = Bitmap.createBitmap(width, height, src.getConfig());

	int A, R, G, B;
	int sumR, sumG, sumB;
	int[][] pixels = new int[3][3];
	for(int y = 0; y < height - 2; ++y) {
		for(int x = 0; x < width - 2; ++x) {
			//      get pixel matrix
			for(int i = 0; i < 3; ++i) {
				for(int j = 0; j < 3; ++j) {
					pixels[i][j] = src.getPixel(x + i, y + j);
				}
			}
			// get alpha of center pixel
			A = Color.alpha(pixels[1][1]);
			// init color sum
			sumR = sumG = sumB = 0;
			sumR = (type*Color.red(pixels[1][1])) - Color.red(pixels[0][0]) - Color.red(pixels[0][2]) - Color.red(pixels[2][0]) - Color.red(pixels[2][2]);
			sumG = (type*Color.green(pixels[1][1])) - Color.green(pixels[0][0]) - Color.green(pixels[0][2]) - Color.green(pixels[2][0]) - Color.green(pixels[2][2]);
			sumB = (type*Color.blue(pixels[1][1])) - Color.blue(pixels[0][0]) - Color.blue(pixels[0][2]) - Color.blue(pixels[2][0]) - Color.blue(pixels[2][2]);
			// get final Red
			R = (int)(sumR  + threshold);
			if(R < 0) { R = 0; }
			else if(R > 255) { R = 255; }
			// get final Green
			G = (int)(sumG  + threshold);
			if(G < 0) { G = 0; }
			else if(G > 255) { G = 255; }
			// get final Blue
			B = (int)(sumB  + threshold);
			if(B < 0) { B = 0; }
			else if(B > 255) { B = 255; }

			result.setPixel(x + 1, y + 1, Color.argb(A, R, G, B));
		}
	}

	src.recycle();
	src = null;

	return result;
}
 
Example 20
Source File: ColorUtils.java    From twitter-kit-android with Apache License 2.0 3 votes vote down vote up
/**
 * This method uses HSL to determine in a human eyesight terms if a color is light or not.
 * See: http://en.wikipedia.org/wiki/HSL_and_HSV. The threshold values are from ITU Rec. 709
 * http://en.wikipedia.org/wiki/Rec._709#Luma_coefficients
 *
 *
 * @param  color A color value
 * @param  factor A factor of lightness measured between 0-1.0
 * @return Whether or not the color is considered light
 */
public static boolean isLightColor(final int color, final float factor) {
    final int r = Color.red(color);
    final int g = Color.green(color);
    final int b = Color.blue(color);

    final double threshold = 0.21 * r + 0.72 * g + 0.07 * b;
    return threshold > (RGB_TOTAL_COLORS * factor);
}