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

setSelectorPoint(x, y) crashes #45

Closed abdalmoniem closed 4 years ago

abdalmoniem commented 4 years ago

I have a ColorPickerView and I want to move the selector position, I do the following:

Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.add_option_dialog);
ColorPickerView foregroundColorPickerView = 
dialog.findViewById((R.id.foregroundColorPickerView));
AlphaSlideBar foregroundAlphaSlideBar = dialog.findViewById(R.id.foregroundAlphaSlideBar);
BrightnessSlideBar foregroundBrightnessSlideBar = dialog.findViewById(R.id.foregroundBrightnessSlideBar);
foregroundColorPickerView.setSelectorPoint(1, 1);

when I run the application, I get the following error:

Caused by: java.lang.IllegalArgumentException: x must be < bitmap.width()
        at android.graphics.Bitmap.checkPixelAccess(Bitmap.java:1962)
        at android.graphics.Bitmap.getPixel(Bitmap.java:1870)
        at com.skydoves.colorpickerview.ColorPickerView.getColorFromBitmap(ColorPickerView.java:305)
        at com.skydoves.colorpickerview.PointMapper.getColorPoint(PointMapper.java:27)
        at com.skydoves.colorpickerview.ColorPickerView.setSelectorPoint(ColorPickerView.java:524)
        at com.hifnawy.prizewheeldescisionmaker.WheelSettingsActivity.addOption(WheelSettingsActivity.java:213)
skydoves commented 4 years ago

Hi, it seems the setSelectorPoint method was called before initializing the ColorPickerView. Could you try the below code?

foregroundColorPickerView.post(new Runnable() {
  foregroundColorPickerView.setSelectorPoint(1, 1);
 });
abdalmoniem commented 4 years ago

It worked, thank you 😊