本文整理汇总了Java中android.graphics.Color.rgb方法的典型用法代码示例。如果您正苦于以下问题:Java Color.rgb方法的具体用法?Java Color.rgb怎么用?Java Color.rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Color
的用法示例。
在下文中一共展示了Color.rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSizeChanged
import android.graphics.Color; //导入方法依赖的package包/类
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mCx = w / 2;
mCy = h / 2;
mSweepGradient = new SweepGradient(mCx, mCy,
new int[]{Color.argb(25, 0, 255, 0),
Color.argb(80, 0, 255, 0),
Color.argb(200, 0, 255, 0)},
new float[]{0, 0.95f, 1.0f});
mPaint = new Paint();
mPaint.setShader(mSweepGradient);
mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCircleDividerColor = Color.BLACK;
mCrossDividerColor = Color.WHITE;
mRadarBgColor = Color.rgb(154, 154, 154);
mDividerPaint.setColor(mCircleDividerColor);
mDividerPaint.setStrokeWidth(3);
mDividerPaint.setStyle(Paint.Style.STROKE);
}
示例2: calculateAverageColor
import android.graphics.Color; //导入方法依赖的package包/类
public static int calculateAverageColor(android.graphics.Bitmap bitmap, int pixelSpacing) {
int R = 0;
int G = 0;
int B = 0;
int height = bitmap.getHeight();
int width = bitmap.getWidth();
int n = 0;
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
for (int i = 0; i < pixels.length; i += pixelSpacing) {
int color = pixels[i];
R += Color.red(color);
G += Color.green(color);
B += Color.blue(color);
n++;
}
return Color.rgb(R / n, G / n, B / n);
}
示例3: readColor
import android.graphics.Color; //导入方法依赖的package包/类
private int readColor() {
long red = 0;
long green = 0;
long blue = 0;
long count = 0;
for (int y = 0; y < bitmap.getHeight(); y++) {
for (int x = 0; x < bitmap.getWidth(); x++) {
int c = bitmap.getPixel(x, y);
count++;
red += Color.red(c);
green += Color.green(c);
blue += Color.blue(c);
}
}
return Color.rgb((int) (red / count), (int) (green / count), (int) (blue / count));
}
示例4: setTextHilighted
import android.graphics.Color; //导入方法依赖的package包/类
public static void setTextHilighted(TextView textView, String text,SearchElement searchElement) {
textView.setText(text);
if (textView == null
|| TextUtils.isEmpty(text)
|| searchElement ==null) {
return;
}
int startIndex = searchElement.startIndex;
int endIndex = searchElement.endIndex;
if (startIndex < 0 || endIndex > text.length()) {
return;
}
// 开始高亮处理
int color = Color.rgb(69, 192, 26);
textView.setText(text, BufferType.SPANNABLE);
Spannable span = (Spannable) textView.getText();
span.setSpan(new ForegroundColorSpan(color), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例5: randomColor
import android.graphics.Color; //导入方法依赖的package包/类
/**
* 随机颜色
*/
public static int randomColor() {
Random random = new Random();
int red = random.nextInt(150) + 50;//50-199
int green = random.nextInt(150) + 50;//50-199
int blue = random.nextInt(150) + 50;//50-199
return Color.rgb(red, green, blue);
}
示例6: setTint
import android.graphics.Color; //导入方法依赖的package包/类
public static void setTint(@NonNull SwitchCompat switchCompat, @ColorInt int color) {
int[] colors = new int[]{color, Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236), Color.rgb(236, 236, 236)};
int[][] states = new int[6][];
states[0] = new int[]{android.R.attr.state_checked, android.R.attr.state_enabled};
states[1] = new int[]{android.R.attr.state_enabled, android.R.attr.state_focused};
states[2] = new int[]{android.R.attr.state_enabled};
states[3] = new int[]{android.R.attr.state_focused};
states[4] = new int[]{android.R.attr.state_window_focused};
states[5] = new int[]{};
switchCompat.setThumbTintList(new ColorStateList(states, colors));
}
示例7: blendColors
import android.graphics.Color; //导入方法依赖的package包/类
/**
* 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);
}
示例8: blendColors
import android.graphics.Color; //导入方法依赖的package包/类
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);
}
示例9: switchColor
import android.graphics.Color; //导入方法依赖的package包/类
/**
* generates random colors for the ProgressBar
*/
protected void switchColor() {
Random r = new Random();
int randomColor = Color.rgb(r.nextInt(256), r.nextInt(256), r.nextInt(256));
mHoloCircularProgressBar.setProgressColor(randomColor);
randomColor = Color.rgb(r.nextInt(256), r.nextInt(256), r.nextInt(256));
mHoloCircularProgressBar.setProgressBackgroundColor(randomColor);
}
示例10: darker
import android.graphics.Color; //导入方法依赖的package包/类
public static int darker(int color) {
int r = Color.red(color);
int b = Color.blue(color);
int g = Color.green(color);
return Color.rgb((int) (r * .9), (int) (g * .9), (int) (b * .9));
}
示例11: getMixedColor
import android.graphics.Color; //导入方法依赖的package包/类
@ColorInt
public static int getMixedColor(@ColorInt int color1, @ColorInt int color2) {
return Color.rgb(
(Color.red(color1) + Color.red(color2)) / 2,
(Color.green(color1) + Color.green(color2)) / 2,
(Color.blue(color1) + Color.blue(color2)) / 2
);
}
示例12: generateRandomColor
import android.graphics.Color; //导入方法依赖的package包/类
private int generateRandomColor() {
int red = ((int) (Math.random() * 255));
int green = ((int) (Math.random() * 255));
int blue = ((int) (Math.random() * 255));
return Color.rgb(red, green, blue);
}
示例13: getBackgroundColor
import android.graphics.Color; //导入方法依赖的package包/类
@Override
public int getBackgroundColor() {
return Color.rgb(158, 195, 255);
}
示例14: getPrimaryColorByCube
import android.graphics.Color; //导入方法依赖的package包/类
public int getPrimaryColorByCube() {
int rank = 0;
int color = 0;
int x = 0;
int y = 0;
int z = 0;
for (AdjacentColorCube cube : cubes) {
if (cube != null) {
int cubeRank = 0;
int cubeColor = 0;
int totalRank = 0;
int[] frequency = cube.getFrequency();
int cubeX = 0;
int cubeY = 0;
int cubeZ = 0;
for (int item : frequency) {
if (item > cubeRank) {
cubeRank = item;
cubeColor = Color.rgb(x + cubeX, y + cubeY, z + cubeZ);
}
totalRank += item;
cubeZ++;
if (cubeZ >= AdjacentColorCube.DIMENSION) {
cubeZ = 0;
cubeY++;
if (cubeY >= AdjacentColorCube.DIMENSION) {
cubeY = 0;
cubeX++;
}
}
}
if (totalRank > rank) {
rank = totalRank;
color = cubeColor;
}
}
z += AdjacentColorCube.DIMENSION;
if (z >= 256) {
z = 0;
y += AdjacentColorCube.DIMENSION;
if (y >= 256) {
y = 0;
x += AdjacentColorCube.DIMENSION;
}
}
}
return color;
}
示例15: HSLToColor
import android.graphics.Color; //导入方法依赖的package包/类
@ColorInt
public static int HSLToColor(@NonNull float[] hsl) {
float h = hsl[0];
float s = hsl[1];
float l = hsl[2];
float c = (1.0f - Math.abs((2.0f * l) - 1.0f)) * s;
float m = l - (0.5f * c);
float x = c * (1.0f - Math.abs(((h / 60.0f) % 2.0f) - 1.0f));
int r = 0;
int g = 0;
int b = 0;
switch (((int) h) / 60) {
case 0:
r = Math.round(255.0f * (c + m));
g = Math.round(255.0f * (x + m));
b = Math.round(255.0f * m);
break;
case 1:
r = Math.round(255.0f * (x + m));
g = Math.round(255.0f * (c + m));
b = Math.round(255.0f * m);
break;
case 2:
r = Math.round(255.0f * m);
g = Math.round(255.0f * (c + m));
b = Math.round(255.0f * (x + m));
break;
case 3:
r = Math.round(255.0f * m);
g = Math.round(255.0f * (x + m));
b = Math.round(255.0f * (c + m));
break;
case 4:
r = Math.round(255.0f * (x + m));
g = Math.round(255.0f * m);
b = Math.round(255.0f * (c + m));
break;
case 5:
case 6:
r = Math.round(255.0f * (c + m));
g = Math.round(255.0f * m);
b = Math.round(255.0f * (x + m));
break;
}
return Color.rgb(constrain(r, 0, 255), constrain(g, 0, 255), constrain(b, 0, 255));
}