Giter Site home page Giter Site logo

Comments (5)

mg6maciej avatar mg6maciej commented on August 20, 2024

If you want to return the exact same color you send, you need to have both SaturationBar and ValueBar assigned to ColorPicker.

colorPicker.addSaturationBar(saturationBar);
colorPicker.addValueBar(valueBar);

This is because HSV colors consist of these three values.

I'm not sure what is SVBar for here. I initially wanted to use that and had the same issue. It could be replaced with SVTriangle like on this image: http://pl.wikipedia.org/wiki/Plik:HSV_cone.jpg

@LarsWerkman Very nice design, thank you for putting it on maven central.

from holocolorpicker.

mg6maciej avatar mg6maciej commented on August 20, 2024

Oh. I translated your colors to hex (#99CC00 and #9ACC00) and I think the reason here is different. I haven't looked at the code yet, but I guess color is kept inside the library as HSV, when you always set and get it as RGB. Some bits are simply lost in the translation.

from holocolorpicker.

LarsWerkman avatar LarsWerkman commented on August 20, 2024

@mg6maciej yes that is exactly what is happening. the reason for this is when setting a color in the color picker you have to translate this to a radial value for the colorpicker and a value for the bars.
and then when you get a value the request the radial value from the colorpicker. thats why you lose some accuracy of the value you put in.
@huteri

from holocolorpicker.

mg6maciej avatar mg6maciej commented on August 20, 2024

I'm not sure this should be closed without resolving.

When using ColorPicker.setColor followed by ColorPicker.getColor, I would expect to get the exact same value at least when all additional Views (saturation, value) are attached.

It's even more important if you use ColorPicker together with 3 NumberPickers which enable you to set any RGB value. When you change one of the RGB values, it updates ColorPicker and OnColorChangeListener is fired to update NumberPickers with value often different than original by 1 bit. This blocks user from swiping up/down to change RGB value.

Relevant code:

    colorPicker.setOnColorChangedListener(new ColorPicker.OnColorChangedListener() {
        @Override
        public void onColorChanged(int color) {
            redPicker.setValue(Color.red(color));
            greenPicker.setValue(Color.green(color));
            bluePicker.setValue(Color.blue(color));
        }
    });
    NumberPicker.OnValueChangeListener listener = new NumberPicker.OnValueChangeListener() {
        @Override
        public void onValueChange(NumberPicker numberPicker, int oldValue, int newValue) {
            int color = Color.rgb(redPicker.getValue(), greenPicker.getValue(), bluePicker.getValue());
            colorPicker.setColor(color);
        }
    };
    redPicker.setOnValueChangedListener(listener);
    greenPicker.setOnValueChangedListener(listener);
    bluePicker.setOnValueChangedListener(listener);

I have made a quick fix for this case: mg6maciej@6f8dd87. It's not a complete solution, but works well with saturation + value bars.

Ideally ColorPicker should keep the value in RGB and only use HSV for displaying purposes.

from holocolorpicker.

mreinerth avatar mreinerth commented on August 20, 2024

here is my version of the quickfix from mg6maciej https://github.com/mreinerth/HoloColorPicker/compare/hotfix/SetColor_GetColor_consistency. Works perfect for me to fix the problem that u dont get the right color u set before. I use the Colorpicker in a dialog and have additionally a gridview under the picker and bars with predefined colors where a click set the color of the picker and the ok button of the dialog save the color (obtained by getColor) to use as a draw color. When i open the Dialog with the picker i set the oldCentercolor and the color to my saved color value.

from holocolorpicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.