skydoves / ColorPickerView

🎨 Android colorpicker for getting colors from any images by tapping on the desired color.
Apache License 2.0
1.58k stars 212 forks source link

Color Picker Brightness and Alpha slider issue on a #92

Open chazilian opened 2 years ago

chazilian commented 2 years ago

Please complete the following information:

Describe the Bug:

When using the colorPickerDialog.colorPickerView.setPaletteDrawable loading in an image that the user has previously drawn. When the color picker dialog appears, the image shows up fine on it. However, an issue arises when I select certain drawn lines that have had their brightness reduced. The color that is being given by the ColorEnvelope is a color that has its brightness set to Max. This becomes really bad when I try to select the color black and the ColorEnvelope returns the color white.

I have included a code snippet of color picker dialog being used I also included screenshots of the color picker using the color wheel and using an image

    private fun openEyeDropper() {
        try {
            val bubbleFlag = CustomFlag(requireContext(), R.layout.bubble_flag)
            bubbleFlag.flagMode = FlagMode.LAST

            val colorPickerDialog = ColorPickerDialog.Builder(requireContext())
                .setTitle("Color Eye Dropper")
                .setPositiveButton(getString(R.string.confirm),
                    ColorEnvelopeListener { envelope, fromUser ->
                        defaultColor = envelope.color
                        draw_View.setDrawingColor(envelope.color)
                        changeToolColors()
                    })
                .setNegativeButton(
                    getString(R.string.cancel)
                ) { dialogInterface, i -> dialogInterface.dismiss() }
                .attachAlphaSlideBar(false) // the default value is true.
                .attachBrightnessSlideBar(true) // the default value is true.
                .setBottomSpace(12) // set a bottom space between the last slidebar and buttons.

            colorPickerDialog.colorPickerView.setPaletteDrawable(draw_View.bitmap.toDrawable(requireContext().resources))
            colorPickerDialog.colorPickerView.flagView = bubbleFlag
            colorPickerDialog.show()
        } catch (e: Exception){
            Log.e( "Error Exception" , e.message.toString())
        }
    }

Picking a color and lowering the brightness 01 08 2022_01 46 08_REC Color picker making black have max brightness 01 08 2022_01 16 45_REC Color picker making the same color I just picked have max brightness 01 08 2022_01 15 25_REC

Expected Behavior:

What I expect to happen when I select a point on an image is that it returns the color and retains the same brightness level and alpha level.

Suggestion The issue seems to occur in the AbstractSliderclass on the notifyColor method. It calls colorPickerView.getPureColor() which seems to reset the alpha and brightness levels. I do understand why this implementation is important when using the color wheel, however, I think an image should allow you to retain the alpha and brightness values of a color point. Especially if you use the default color wheel to create a drawing and you want to retrieve a previous color from it. A possible solution could be giving a flag to the color listener to see if it using the color wheel or a custom image. Then in the color listener, you can check if it is an image and if it is then you don't have to reset the alpha and brightness of a color.