Java Code Examples for android.graphics.Color#HSVToColor
The following examples show how to use
android.graphics.Color#HSVToColor .
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: ColorShadeFactory.java From color-picker with Apache License 2.0 | 6 votes |
@Override public int colorAt(int index, int count) { index++; count++; float[] hsl = mHSL; if (index <= count / 2) { hsl[1] = 1f; hsl[2] = index * 2f / count; } else { hsl[1] = 2f - index * 2f / count; hsl[2] = 1f; } return Color.HSVToColor(255, hsl); }
Example 2
Source File: HsvEvaluator.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
@Override public Integer evaluate(float fraction, Integer startValue, Integer endValue) { float[] startHsv = new float[3]; float[] endHsv = new float[3]; float[] currentHsv = new float[3]; Color.colorToHSV(startValue, startHsv); Color.colorToHSV(endValue, endHsv); for (int i = 0; i < 3; i++) { currentHsv[i] = (1 - fraction) * startHsv[i] + fraction * endHsv[i]; } while (currentHsv[0] >= 360.0f) { currentHsv[0] -= 360.0f; } while (currentHsv[0] < 0.0f) { currentHsv[0] += 360.0f; } return Color.HSVToColor(currentHsv); }
Example 3
Source File: ThemeEditorView.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private Bitmap createColorWheelBitmap(int width, int height) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); int colorCount = 12; int colorAngleStep = 360 / 12; int[] colors = new int[colorCount + 1]; float[] hsv = new float[]{0.0f, 1.0f, 1.0f}; for (int i = 0; i < colors.length; i++) { hsv[0] = (i * colorAngleStep + 180) % 360; colors[i] = Color.HSVToColor(hsv); } colors[colorCount] = colors[0]; SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null); RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xffffffff, 0x00ffffff, Shader.TileMode.CLAMP); ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER); colorWheelPaint.setShader(composeShader); Canvas canvas = new Canvas(bitmap); canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint); return bitmap; }
Example 4
Source File: Utils.java From FireFiles with Apache License 2.0 | 5 votes |
public static int getComplementaryColor(int colorToInvert) { float[] hsv = new float[3]; Color.RGBToHSV(Color.red(colorToInvert), Color.green(colorToInvert), Color.blue(colorToInvert), hsv); hsv[0] = (hsv[0] + 180) % 360; return Color.HSVToColor(hsv); }
Example 5
Source File: Message.java From Atomic with GNU General Public License v3.0 | 5 votes |
/** * Associate a color with a sender name * * @return a color hexa */ public static int getSenderColor(String sender, ColorScheme scheme) { /* It might be worth to use some hash table here */ if( sender == null ) { return scheme.getForeground(); } if( !App.getSettings().showColorsNick() ) { return scheme.getForeground(); } int color = 0; int variant = sender.charAt(0); for( int i = 0; i < sender.length(); i++ ) { char c = sender.charAt(i); if( c - 33 > 'Z' ) variant += (c - 33) % 32; else variant -= (c - 33) % 32; color += c; } variant %= 20; // We don't want the color to be the background color. final int bg = scheme.getBackground(); int tmpColor;// = _scheme.getMircColor(color); do { float[] hsv = new float[3]; Color.colorToHSV(scheme.getMircColor(color++), hsv); hsv[0] += variant; tmpColor = Color.HSVToColor(hsv); } while ( likeness(bg, tmpColor) < 30 ); return tmpColor; //colors[color]; }
Example 6
Source File: HSV.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
@Override public int evaluateColor(List<Channel> channels) { return Color.HSVToColor(new float[]{ ((float) channels.get(0).getProgress()), ((float) channels.get(1).getProgress()) / 100, ((float) channels.get(2).getProgress()) / 100 }); }
Example 7
Source File: Colour.java From Colours with MIT License | 5 votes |
public static int[] monochromaticColors(float[] hsv) { float[] CA1 = {hsv[0], (float) (hsv[1]), (float) (hsv[2] / 2)}; float[] CA2 = {hsv[0], (float) (hsv[1] / 2), (float) (hsv[2] / 3)}; float[] CB1 = {hsv[0], (float) (hsv[1] / 3), (float) (hsv[2] * 2 / 3)}; float[] CB2 = {hsv[0], (float) (hsv[1]), (float) (hsv[2] * 4 / 5)}; return new int[]{Color.HSVToColor(CA1), Color.HSVToColor(CA2), Color.HSVToColor(CB1), Color.HSVToColor(CB2)}; }
Example 8
Source File: ColorPickerView.java From fanfouapp-opensource with Apache License 2.0 | 5 votes |
private int[] buildHueColorArray() { final int[] hue = new int[361]; int count = 0; for (int i = hue.length - 1; i >= 0; i--, count++) { hue[count] = Color.HSVToColor(new float[] { i, 1f, 1f }); } return hue; }
Example 9
Source File: ColorStateDrawable.java From ColorPicker with Apache License 2.0 | 5 votes |
/** * Given a particular color, adjusts its value by a multiplier. */ private static int getPressedColor(int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] = hsv[2] * PRESSED_STATE_MULTIPLIER; return Color.HSVToColor(hsv); }
Example 10
Source File: Utils.java From FireFiles with Apache License 2.0 | 5 votes |
public static int getComplementaryColor(int colorToInvert) { float[] hsv = new float[3]; Color.RGBToHSV(Color.red(colorToInvert), Color.green(colorToInvert), Color.blue(colorToInvert), hsv); hsv[0] = (hsv[0] + 180) % 360; return Color.HSVToColor(hsv); }
Example 11
Source File: ColorUtils.java From q-municate-android with Apache License 2.0 | 5 votes |
public int getRandomColor() { float[] hsv = new float[3]; int color = Color.argb(COLOR_MAX_VALUE, random.nextInt(COLOR_MAX_VALUE), random.nextInt( COLOR_MAX_VALUE), random.nextInt(COLOR_MAX_VALUE)); Color.colorToHSV(color, hsv); hsv[2] *= COLOR_ALPHA; color = Color.HSVToColor(hsv); return color; }
Example 12
Source File: ColorPickerView.java From droidddle with Apache License 2.0 | 5 votes |
public void setAlphaValue(float alpha) { this.alpha = alpha; this.initialColor = Color.HSVToColor(Utils.alphaValueAsInt(this.alpha), currentColorCircle.getHsvWithLightness(this.lightness)); if (this.colorEdit != null) this.colorEdit.setText("#" + Integer.toHexString(this.initialColor).toUpperCase()); if (this.lightnessSlider != null && this.initialColor != null) this.lightnessSlider.setColor(this.initialColor); updateColorWheel(); invalidate(); }
Example 13
Source File: ColorCircle.java From timecat with Apache License 2.0 | 5 votes |
public void set(float x, float y, float[] hsv) { this.x = x; this.y = y; this.hsv[0] = hsv[0]; this.hsv[1] = hsv[1]; this.hsv[2] = hsv[2]; this.color = Color.HSVToColor(this.hsv); }
Example 14
Source File: SVBar.java From memoir with Apache License 2.0 | 5 votes |
/** * Calculate the color selected by the pointer on the bar. * * @param coord Coordinate of the pointer. */ private void calculateColor(int coord) { coord = coord - mBarPointerHaloRadius; if (coord < 0) { coord = 0; } else if (coord > mBarLength) { coord = mBarLength; } if (coord > (mBarPointerHaloRadius + (mBarLength / 2)) && coord < (mBarPointerHaloRadius + mBarLength)) { mColor = Color .HSVToColor(new float[]{ mHSVColor[0], 1f, (float) (1 - (mPosToSVFactor * (coord - (mBarPointerHaloRadius + (mBarLength / 2)))))}); } else if (coord > mBarPointerHaloRadius && coord < (mBarPointerHaloRadius + mBarLength)) { mColor = Color.HSVToColor(new float[]{mHSVColor[0], (float) ((mPosToSVFactor * (coord - mBarPointerHaloRadius))), 1f}); } else if (coord == mBarPointerHaloRadius) { mColor = Color.WHITE; } else if (coord == mBarPointerHaloRadius + mBarLength) { mColor = Color.BLACK; } }
Example 15
Source File: DefaultButtonController.java From ProgressRoundButton with Apache License 2.0 | 5 votes |
/** * 由右边的颜色算出左边的颜色(左边的颜色比右边的颜色降饱和度30%,亮度增加30%) * + * * @param color * @return */ public int getLighterColor(int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[1] -= 0.3f; hsv[2] += 0.3f; return Color.HSVToColor(hsv); }
Example 16
Source File: ColorPickerView.java From ColorPicker with Apache License 2.0 | 4 votes |
private void drawAlphaPanel(Canvas canvas) { /* * Will be drawn with hw acceleration, very fast. * Also the AlphaPatternDrawable is backed by a bitmap * generated only once if the size does not change. */ if (!showAlphaPanel || alphaRect == null || alphaPatternDrawable == null) return; final Rect rect = alphaRect; if (BORDER_WIDTH_PX > 0) { borderPaint.setColor(borderColor); canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, borderPaint); } alphaPatternDrawable.draw(canvas); float[] hsv = new float[] { hue, sat, val }; int color = Color.HSVToColor(hsv); int acolor = Color.HSVToColor(0, hsv); alphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top, color, acolor, TileMode.CLAMP); alphaPaint.setShader(alphaShader); canvas.drawRect(rect, alphaPaint); if (alphaSliderText != null && !alphaSliderText.equals("")) { canvas.drawText(alphaSliderText, rect.centerX(), rect.centerY() + DrawingUtils.dpToPx(getContext(), 4), alphaTextPaint); } Point p = alphaToPoint(alpha); RectF r = new RectF(); r.left = p.x - (sliderTrackerSizePx / 2); r.right = p.x + (sliderTrackerSizePx / 2); r.top = rect.top - sliderTrackerOffsetPx; r.bottom = rect.bottom + sliderTrackerOffsetPx; canvas.drawRoundRect(r, 2, 2, hueAlphaTrackerPaint); }
Example 17
Source File: ColorPickerView.java From color-picker-view with Apache License 2.0 | 4 votes |
private void drawHuePanel(Canvas canvas){ final Rect rect = mHueRect; if(BORDER_WIDTH_PX > 0) { mBorderPaint.setColor(mBorderColor); canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint); } if(mHueBackgroundCache == null) { mHueBackgroundCache = new BitmapCache(); mHueBackgroundCache.bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Config.ARGB_8888); mHueBackgroundCache.canvas = new Canvas(mHueBackgroundCache.bitmap); int[] hueColors = new int[(int)(rect.height() + 0.5f)]; // Generate array of all colors, will be drawn as individual lines. float h = 360f; for(int i = 0; i < hueColors.length; i++) { hueColors[i] = Color.HSVToColor(new float[]{h, 1f,1f}); h -= 360f / hueColors.length; } // Time to draw the hue color gradient, // its drawn as individual lines which // will be quite many when the resolution is high // and/or the panel is large. Paint linePaint = new Paint(); linePaint.setStrokeWidth(0); for(int i = 0; i < hueColors.length; i++) { linePaint.setColor(hueColors[i]); mHueBackgroundCache.canvas.drawLine(0, i, mHueBackgroundCache.bitmap.getWidth(), i, linePaint); } } canvas.drawBitmap(mHueBackgroundCache.bitmap, null, rect, null); Point p = hueToPoint(mHue); RectF r = new RectF(); r.left = rect.left - mSliderTrackerOffsetPx; r.right = rect.right + mSliderTrackerOffsetPx; r.top = p.y - (mSliderTrackerSizePx / 2); r.bottom = p.y + (mSliderTrackerSizePx / 2); canvas.drawRoundRect(r, 2, 2, mHueAlphaTrackerPaint); }
Example 18
Source File: ConvertUtils.java From AndroidDownload with Apache License 2.0 | 4 votes |
public static int toDarkenColor(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float value) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= value;//HSV指Hue、Saturation、Value,即色调、饱和度和亮度,此处表示修改亮度 return Color.HSVToColor(hsv); }
Example 19
Source File: ConvertUtils.java From FilePicker with MIT License | 4 votes |
public static int toDarkenColor(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float value) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= value;//HSV指Hue、Saturation、Value,即色调、饱和度和亮度,此处表示修改亮度 return Color.HSVToColor(hsv); }
Example 20
Source File: ColorPickerView.java From color-picker-view with Apache License 2.0 | 2 votes |
/** * Get the current color this view is showing. * @return the current color. */ public int getColor(){ return Color.HSVToColor(mAlpha, new float[]{mHue,mSat,mVal}); }