Goal is to find which rectangle contains goalColor, then find the pixel within that rectangle that is closest to goalColor. Goal is to find pixel closest to a given color, " Color goalColor".Ĭonsider each tall, thin rectangle whose corners are two topColors and the corresponding two bottomColors. The pixel colors are linearly interpolated from top row to bottom row. The bottom row (y=maxY) has darkenedColors, evenly spaced across x. The top row (y=0) has saturatedColors, evenly spaced across x. Private int maxX, maxY // From your UI rectangle. Private int nColors => saturatedColors.Count Use the original Colors from which the SkColors were generated, for easier manipulation. Rename the color lists so easier to work with. Lets look at how that rectangular image was generated. What is needed, is a mathematical formula that corresponds to what is drawn. This is the beginning of an answer to that. Going down the screen, the palette reduces Value to near zero. Your ColorList should have fully Saturated colors at max Value. Your palette looks like the rectangle labeled S(HSV) = 1. In wiki HSL-HSV models, click on diagram at right. ![]() The palette you show is an approximation to an "HSV" color model. You'll need a separate "saturation" slider, to allow picking of any color. How calculate (x,y) coordinates that correspond to a given color?įirst, an observation. Given: A color palette generated by [see OnPaintSurface code, starting at // Draw gradient rainbow Color spectrum. Link back to this question, so you don't have to repeat the information that gives additional background/context.) ![]() Include in that post the essential details needed to understand that question. (To ask a second question, please make a new post. StackOverflow is designed for each post to ask and answer one coding question. My question is: Is generating string with parameters the only way to go (Color Hex code, as well as X and Y coordinates)? Is there some possibility to place pointer on control initialization by provided color in some efficient way without constant loop iteration and freeze of UI? New Color(255, 0, 255).ToHex(), // FuchsiaĭefaultBindingMode: BindingMode.OneTime, null) Public static readonly BindableProperty ColorListProperty & () != Color.FromHex("#FFFFFFFF").ToSKColor())ĭebug.WriteLine(String.Format("Color: It looks like before color picker is actually generated image is black and white? This is of course not a good solution in real case scenario as picked color can be white or black: During initialization there is problem with black and white colors #00000000 and #FFFFFFFF.Not always providing correct coordinates.Loop iteration for reading pixels is freezing UI, especially for larger color pickers (large image).I have been getting familiar with possibility to read pixels, searching for needed color and getting it's coordinates. It is working, however this is adding additional complexity for combining strings and then parsing them inside ViewModels. ![]() I have got a work-around where I save all needed parameters into string (Color Hex code, as well as X and Y coordinates). This means if I will provide previously selected color for Color picker control it will not be able to place pointer in a right place, because it is waiting for X, Y coordinates and not color. ![]() Color picker is initialized on previously selected colorĬurrently picker is taking in account only coordinates of pointer X and Y.However I would like to have possibility to set "selectedColor" on initialization. Everything seems to be working as expected. I am currently trying to modify color picker control.
0 Comments
Leave a Reply. |