当前位置: 首页>>代码示例>>Java>>正文


Java Color.RGBToHSV方法代码示例

本文整理汇总了Java中android.graphics.Color.RGBToHSV方法的典型用法代码示例。如果您正苦于以下问题:Java Color.RGBToHSV方法的具体用法?Java Color.RGBToHSV怎么用?Java Color.RGBToHSV使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Color的用法示例。


在下文中一共展示了Color.RGBToHSV方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setColor

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Set the color this view should show.
 *
 * @param color    The color that should be selected. #argb
 * @param callback If you want to get a callback to your OnColorChangedListener.
 */
public void setColor(int color, boolean callback) {

    int alpha = Color.alpha(color);
    int red = Color.red(color);
    int blue = Color.blue(color);
    int green = Color.green(color);

    float[] hsv = new float[3];

    Color.RGBToHSV(red, green, blue, hsv);

    this.alpha = alpha;
    hue = hsv[0];
    sat = hsv[1];
    val = hsv[2];

    if (callback && onColorChangedListener != null) {
        onColorChangedListener
                .onColorChanged(Color.HSVToColor(this.alpha, new float[]{hue, sat, val}));
    }

    invalidate();
}
 
开发者ID:nhocga1995s,项目名称:MyCalendar,代码行数:30,代码来源:ColorPickerView.java

示例2: setColor

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Set the color this view should show.
 *
 * @param color
 *     The color that should be selected. #argb
 * @param callback
 *     If you want to get a callback to your OnColorChangedListener.
 */
public void setColor(int color, boolean callback) {

  int alpha = Color.alpha(color);
  int red = Color.red(color);
  int blue = Color.blue(color);
  int green = Color.green(color);

  float[] hsv = new float[3];

  Color.RGBToHSV(red, green, blue, hsv);

  this.alpha = alpha;
  hue = hsv[0];
  sat = hsv[1];
  val = hsv[2];

  if (callback && onColorChangedListener != null) {
    onColorChangedListener
        .onColorChanged(Color.HSVToColor(this.alpha, new float[]{hue, sat, val}));
  }

  invalidate();
}
 
开发者ID:Blankeer,项目名称:MDWechat,代码行数:32,代码来源:ColorPickerView.java

示例3: setColor

import android.graphics.Color; //导入方法依赖的package包/类
/**
 * Set the color this view should show.
 * @param color The color that should be selected. #argb
 * @param callback If you want to get a callback to
 * your OnColorChangedListener.
 */
public void setColor(int color, boolean callback){

	int alpha = Color.alpha(color);
	int red = Color.red(color);
	int blue = Color.blue(color);
	int green = Color.green(color);
	
	float[] hsv = new float[3];
	
	Color.RGBToHSV(red, green, blue, hsv);
	
	mAlpha = alpha;
	mHue = hsv[0];
	mSat = hsv[1];
	mVal = hsv[2];
	
	if(callback && mListener != null){			
		mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[]{mHue, mSat, mVal}));				
	}
	
	invalidate();
}
 
开发者ID:MohammadAlBanna,项目名称:Swift-Braille-Soft-keyboard,代码行数:29,代码来源:ColorPickerView.java

示例4: getComplementaryColor

import android.graphics.Color; //导入方法依赖的package包/类
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);
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:8,代码来源:Utils.java

示例5: runOpMode

import android.graphics.Color; //导入方法依赖的package包/类
@Override
public void runOpMode() {

  // hsvValues is an array that will hold the hue, saturation, and value information.
  float hsvValues[] = {0F,0F,0F};

  // values is a reference to the hsvValues array.
  final float values[] = hsvValues;

  // get a reference to the RelativeLayout so we can change the background
  // color of the Robot Controller app to match the hue detected by the RGB sensor.
  final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(R.id.RelativeLayout);

  // bPrevState and bCurrState represent the previous and current state of the button.
  boolean bPrevState = false;
  boolean bCurrState = false;

  // bLedOn represents the state of the LED.
  boolean bLedOn = true;

  // get a reference to our ColorSensor object.
  colorSensor = hardwareMap.colorSensor.get("sensor_color");

  // Set the LED in the beginning
  colorSensor.enableLed(bLedOn);

  // wait for the start button to be pressed.
  waitForStart();

  // while the op mode is active, loop and read the RGB data.
  // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
  while (opModeIsActive()) {

    // check the status of the x button on either gamepad.
    bCurrState = gamepad1.x;

    // check for button state transitions.
    if ((bCurrState == true) && (bCurrState != bPrevState))  {

      // button is transitioning to a pressed state. So Toggle LED
      bLedOn = !bLedOn;
      colorSensor.enableLed(bLedOn);
    }

    // update previous state variable.
    bPrevState = bCurrState;

    // convert the RGB values to HSV values.
    Color.RGBToHSV(colorSensor.red() * 8, colorSensor.green() * 8, colorSensor.blue() * 8, hsvValues);

    // send the info back to driver station using telemetry function.
    telemetry.addData("LED", bLedOn ? "On" : "Off");
    telemetry.addData("Clear", colorSensor.alpha());
    telemetry.addData("Red  ", colorSensor.red());
    telemetry.addData("Green", colorSensor.green());
    telemetry.addData("Blue ", colorSensor.blue());
    telemetry.addData("Hue", hsvValues[0]);

    // change the background color to match the color detected by the RGB sensor.
    // pass a reference to the hue, saturation, and value array as an argument
    // to the HSVToColor method.
    relativeLayout.post(new Runnable() {
      public void run() {
        relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
      }
    });

    telemetry.update();
  }
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:71,代码来源:SensorMRColor.java

示例6: runOpMode

import android.graphics.Color; //导入方法依赖的package包/类
@Override
public void runOpMode() {

    // get a reference to the color sensor.
    sensorColor = hardwareMap.get(ColorSensor.class, "sensor_color_distance");

    // get a reference to the distance sensor that shares the same name.
    sensorDistance = hardwareMap.get(DistanceSensor.class, "sensor_color_distance");

    // hsvValues is an array that will hold the hue, saturation, and value information.
    float hsvValues[] = {0F, 0F, 0F};

    // values is a reference to the hsvValues array.
    final float values[] = hsvValues;

    // sometimes it helps to multiply the raw RGB values with a scale factor
    // to amplify/attentuate the measured values.
    final double SCALE_FACTOR = 255;

    // get a reference to the RelativeLayout so we can change the background
    // color of the Robot Controller app to match the hue detected by the RGB sensor.
    int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifier("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
    final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayoutId);

    // wait for the start button to be pressed.
    waitForStart();

    // loop and read the RGB and distance data.
    // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
    while (opModeIsActive()) {
        // convert the RGB values to HSV values.
        // multiply by the SCALE_FACTOR.
        // then cast it back to int (SCALE_FACTOR is a double)
        Color.RGBToHSV((int) (sensorColor.red() * SCALE_FACTOR),
                (int) (sensorColor.green() * SCALE_FACTOR),
                (int) (sensorColor.blue() * SCALE_FACTOR),
                hsvValues);

        // send the info back to driver station using telemetry function.
        telemetry.addData("Distance (cm)",
                String.format(Locale.US, "%.02f", sensorDistance.getDistance(DistanceUnit.CM)));
        telemetry.addData("Alpha", sensorColor.alpha());
        telemetry.addData("Red  ", sensorColor.red());
        telemetry.addData("Green", sensorColor.green());
        telemetry.addData("Blue ", sensorColor.blue());
        telemetry.addData("Hue", hsvValues[0]);

        // change the background color to match the color detected by the RGB sensor.
        // pass a reference to the hue, saturation, and value array as an argument
        // to the HSVToColor method.
        relativeLayout.post(new Runnable() {
            public void run() {
                relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
            }
        });

        telemetry.update();
    }

    // Set the panel back to the default color
    relativeLayout.post(new Runnable() {
        public void run() {
            relativeLayout.setBackgroundColor(Color.WHITE);
        }
    });
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:67,代码来源:SensorREVColorDistance.java

示例7: runOpMode

import android.graphics.Color; //导入方法依赖的package包/类
@Override
public void runOpMode() {

  // hsvValues is an array that will hold the hue, saturation, and value information.
  float hsvValues[] = {0F,0F,0F};

  // values is a reference to the hsvValues array.
  final float values[] = hsvValues;

  // get a reference to the RelativeLayout so we can change the background
  // color of the Robot Controller app to match the hue detected by the RGB sensor.
  int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifier("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
  final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayoutId);

  // bPrevState and bCurrState represent the previous and current state of the button.
  boolean bPrevState = false;
  boolean bCurrState = false;

  // bLedOn represents the state of the LED.
  boolean bLedOn = true;

  // get a reference to our ColorSensor object.
  colorSensor = hardwareMap.colorSensor.get("sensor_color");

  // turn the LED on in the beginning, just so user will know that the sensor is active.
  colorSensor.enableLed(bLedOn);

  // wait for the start button to be pressed.
  waitForStart();

  // loop and read the RGB data.
  // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
  while (opModeIsActive())  {

    // check the status of the x button on gamepad1.
    bCurrState = gamepad1.x;

    // check for button state transitions.
    if (bCurrState && (bCurrState != bPrevState))  {

      // button is transitioning to a pressed state.  Toggle LED.
      // on button press, enable the LED.
      bLedOn = !bLedOn;
      colorSensor.enableLed(bLedOn);
    }

    // update previous state variable.
    bPrevState = bCurrState;

    // convert the RGB values to HSV values.
    Color.RGBToHSV(colorSensor.red(), colorSensor.green(), colorSensor.blue(), hsvValues);

    // send the info back to driver station using telemetry function.
    telemetry.addData("LED", bLedOn ? "On" : "Off");
    telemetry.addData("Clear", colorSensor.alpha());
    telemetry.addData("Red  ", colorSensor.red());
    telemetry.addData("Green", colorSensor.green());
    telemetry.addData("Blue ", colorSensor.blue());
    telemetry.addData("Hue", hsvValues[0]);

    // change the background color to match the color detected by the RGB sensor.
    // pass a reference to the hue, saturation, and value array as an argument
    // to the HSVToColor method.
    relativeLayout.post(new Runnable() {
      public void run() {
        relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
      }
    });

    telemetry.update();
  }

  // Set the panel back to the default color
  relativeLayout.post(new Runnable() {
    public void run() {
      relativeLayout.setBackgroundColor(Color.WHITE);
    }
  });

}
 
开发者ID:SCHS-Robotics,项目名称:Team9261-2017-2018,代码行数:81,代码来源:SensorHTColor.java

示例8: drawHighlighted

import android.graphics.Color; //导入方法依赖的package包/类
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    BubbleData bubbleData = mChart.getBubbleData();

    float phaseY = mAnimator.getPhaseY();

    for (Highlight high : indices) {

        IBubbleDataSet set = bubbleData.getDataSetByIndex(high.getDataSetIndex());

        if (set == null || !set.isHighlightEnabled())
            continue;

        final BubbleEntry entry = set.getEntryForXValue(high.getX(), high.getY());

        if (entry.getY() != high.getY())
            continue;

        if (!isInBoundsX(entry, set))
            continue;

        Transformer trans = mChart.getTransformer(set.getAxisDependency());

        sizeBuffer[0] = 0f;
        sizeBuffer[2] = 1f;

        trans.pointValuesToPixel(sizeBuffer);

        boolean normalizeSize = set.isNormalizeSizeEnabled();

        // calcualte the full width of 1 step on the x-axis
        final float maxBubbleWidth = Math.abs(sizeBuffer[2] - sizeBuffer[0]);
        final float maxBubbleHeight = Math.abs(
                mViewPortHandler.contentBottom() - mViewPortHandler.contentTop());
        final float referenceSize = Math.min(maxBubbleHeight, maxBubbleWidth);

        pointBuffer[0] = entry.getX();
        pointBuffer[1] = (entry.getY()) * phaseY;
        trans.pointValuesToPixel(pointBuffer);

        high.setDraw(pointBuffer[0], pointBuffer[1]);

        float shapeHalf = getShapeSize(entry.getSize(),
                set.getMaxSize(),
                referenceSize,
                normalizeSize) / 2f;

        if (!mViewPortHandler.isInBoundsTop(pointBuffer[1] + shapeHalf)
                || !mViewPortHandler.isInBoundsBottom(pointBuffer[1] - shapeHalf))
            continue;

        if (!mViewPortHandler.isInBoundsLeft(pointBuffer[0] + shapeHalf))
            continue;

        if (!mViewPortHandler.isInBoundsRight(pointBuffer[0] - shapeHalf))
            break;

        final int originalColor = set.getColor((int) entry.getX());

        Color.RGBToHSV(Color.red(originalColor), Color.green(originalColor),
                Color.blue(originalColor), _hsvBuffer);
        _hsvBuffer[2] *= 0.5f;
        final int color = Color.HSVToColor(Color.alpha(originalColor), _hsvBuffer);

        mHighlightPaint.setColor(color);
        mHighlightPaint.setStrokeWidth(set.getHighlightCircleWidth());
        c.drawCircle(pointBuffer[0], pointBuffer[1], shapeHalf, mHighlightPaint);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:71,代码来源:BubbleChartRenderer.java

示例9: runOpMode

import android.graphics.Color; //导入方法依赖的package包/类
@Override
public void runOpMode() {

  // hsvValues is an array that will hold the hue, saturation, and value information.
  float hsvValues[] = {0F,0F,0F};

  // values is a reference to the hsvValues array.
  final float values[] = hsvValues;

  // get a reference to the RelativeLayout so we can change the background
  // color of the Robot Controller app to match the hue detected by the RGB sensor.
  final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(R.id.RelativeLayout);

  // bPrevState and bCurrState represent the previous and current state of the button.
  boolean bPrevState = false;
  boolean bCurrState = false;

  // bLedOn represents the state of the LED.
  boolean bLedOn = true;

  // get a reference to our ColorSensor object.
  colorSensor = hardwareMap.colorSensor.get("sensor_color");

  // turn the LED on in the beginning, just so user will know that the sensor is active.
  colorSensor.enableLed(bLedOn);

  // wait for the start button to be pressed.
  waitForStart();

  // loop and read the RGB data.
  // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
  while (opModeIsActive())  {

    // check the status of the x button on either gamepad.
    bCurrState = gamepad1.x;

    // check for button state transitions.
    if ((bCurrState == true) && (bCurrState != bPrevState))  {

      // button is transitioning to a pressed state.  Toggle LED.
      // on button press, enable the LED.
      bLedOn = !bLedOn;
      colorSensor.enableLed(bLedOn);
    }

    // update previous state variable.
    bPrevState = bCurrState;

    // convert the RGB values to HSV values.
    Color.RGBToHSV(colorSensor.red(), colorSensor.green(), colorSensor.blue(), hsvValues);

    // send the info back to driver station using telemetry function.
    telemetry.addData("LED", bLedOn ? "On" : "Off");
    telemetry.addData("Clear", colorSensor.alpha());
    telemetry.addData("Red  ", colorSensor.red());
    telemetry.addData("Green", colorSensor.green());
    telemetry.addData("Blue ", colorSensor.blue());
    telemetry.addData("Hue", hsvValues[0]);

    // change the background color to match the color detected by the RGB sensor.
    // pass a reference to the hue, saturation, and value array as an argument
    // to the HSVToColor method.
    relativeLayout.post(new Runnable() {
      public void run() {
        relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
      }
    });

    telemetry.update();
  }
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:72,代码来源:SensorHTColor.java

示例10: runOpMode

import android.graphics.Color; //导入方法依赖的package包/类
@Override
public void runOpMode() {

  // hsvValues is an array that will hold the hue, saturation, and value information.
  float hsvValues[] = {0F,0F,0F};

  // values is a reference to the hsvValues array.
  final float values[] = hsvValues;

  // get a reference to the RelativeLayout so we can change the background
  // color of the Robot Controller app to match the hue detected by the RGB sensor.
  final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(R.id.RelativeLayout);

  // bPrevState and bCurrState represent the previous and current state of the button.
  boolean bPrevState = false;
  boolean bCurrState = false;

  // bLedOn represents the state of the LED.
  boolean bLedOn = true;

  // get a reference to our DeviceInterfaceModule object.
  cdim = hardwareMap.deviceInterfaceModule.get("dim");

  // set the digital channel to output mode.
  // remember, the Adafruit sensor is actually two devices.
  // It's an I2C sensor and it's also an LED that can be turned on or off.
  cdim.setDigitalChannelMode(LED_CHANNEL, DigitalChannelController.Mode.OUTPUT);

  // get a reference to our ColorSensor object.
  sensorRGB = hardwareMap.colorSensor.get("sensor_color");

  // turn the LED on in the beginning, just so user will know that the sensor is active.
  cdim.setDigitalChannelState(LED_CHANNEL, bLedOn);

  // wait for the start button to be pressed.
  waitForStart();

  // loop and read the RGB data.
  // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
  while (opModeIsActive())  {

    // check the status of the x button on gamepad.
    bCurrState = gamepad1.x;

    // check for button-press state transitions.
    if ((bCurrState == true) && (bCurrState != bPrevState))  {

      // button is transitioning to a pressed state. Toggle the LED.
      bLedOn = !bLedOn;
      cdim.setDigitalChannelState(LED_CHANNEL, bLedOn);
    }

    // update previous state variable.
    bPrevState = bCurrState;

    // convert the RGB values to HSV values.
    Color.RGBToHSV((sensorRGB.red() * 255) / 800, (sensorRGB.green() * 255) / 800, (sensorRGB.blue() * 255) / 800, hsvValues);

    // send the info back to driver station using telemetry function.
    telemetry.addData("LED", bLedOn ? "On" : "Off");
    telemetry.addData("Clear", sensorRGB.alpha());
    telemetry.addData("Red  ", sensorRGB.red());
    telemetry.addData("Green", sensorRGB.green());
    telemetry.addData("Blue ", sensorRGB.blue());
    telemetry.addData("Hue", hsvValues[0]);

    // change the background color to match the color detected by the RGB sensor.
    // pass a reference to the hue, saturation, and value array as an argument
    // to the HSVToColor method.
    relativeLayout.post(new Runnable() {
      public void run() {
        relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
      }
    });

    telemetry.update();
  }
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:79,代码来源:SensorAdafruitRGB.java

示例11: RGBToHSV

import android.graphics.Color; //导入方法依赖的package包/类
public void RGBToHSV(int red, int green, int blue, float[] hsv) {
    Color.RGBToHSV(red, green, blue, hsv);
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:4,代码来源:Colors.java

示例12: runOpMode

import android.graphics.Color; //导入方法依赖的package包/类
@Override
public void runOpMode() {

  // hsvValues is an array that will hold the hue, saturation, and value information.
  float hsvValues[] = {0F,0F,0F};

  // values is a reference to the hsvValues array.
  final float values[] = hsvValues;

  // get a reference to the RelativeLayout so we can change the background
  // color of the Robot Controller app to match the hue detected by the RGB sensor.
  int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifier("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
  final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayoutId);

  // bPrevState and bCurrState represent the previous and current state of the button.
  boolean bPrevState = false;
  boolean bCurrState = false;

  // bLedOn represents the state of the LED.
  boolean bLedOn = true;

  // get a reference to our ColorSensor object.
  colorSensor = hardwareMap.get(ColorSensor.class, "sensor_color");

  // Set the LED in the beginning
  colorSensor.enableLed(bLedOn);

  // wait for the start button to be pressed.
  waitForStart();

  // while the op mode is active, loop and read the RGB data.
  // Note we use opModeIsActive() as our loop condition because it is an interruptible method.
  while (opModeIsActive()) {

    // check the status of the x button on either gamepad.
    bCurrState = gamepad1.x;

    // check for button state transitions.
    if (bCurrState && (bCurrState != bPrevState))  {

      // button is transitioning to a pressed state. So Toggle LED
      bLedOn = !bLedOn;
      colorSensor.enableLed(bLedOn);
    }

    // update previous state variable.
    bPrevState = bCurrState;

    // convert the RGB values to HSV values.
    Color.RGBToHSV(colorSensor.red() * 8, colorSensor.green() * 8, colorSensor.blue() * 8, hsvValues);

    // send the info back to driver station using telemetry function.
    telemetry.addData("LED", bLedOn ? "On" : "Off");
    telemetry.addData("Clear", colorSensor.alpha());
    telemetry.addData("Red  ", colorSensor.red());
    telemetry.addData("Green", colorSensor.green());
    telemetry.addData("Blue ", colorSensor.blue());
    telemetry.addData("Hue", hsvValues[0]);

    // change the background color to match the color detected by the RGB sensor.
    // pass a reference to the hue, saturation, and value array as an argument
    // to the HSVToColor method.
    relativeLayout.post(new Runnable() {
      public void run() {
        relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
      }
    });

    telemetry.update();
  }

  // Set the panel back to the default color
  relativeLayout.post(new Runnable() {
    public void run() {
      relativeLayout.setBackgroundColor(Color.WHITE);
    }
  });
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:79,代码来源:SensorMRColor.java


注:本文中的android.graphics.Color.RGBToHSV方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。