Is there any way to get color at specific point on canvas, like we use eye-dropper tool. #1421
Replies: 8 comments 6 replies
-
This is an interesting question, you can a access pixel colors via RuntimeShaders: https://shopify.github.io/react-native-skia/docs/image-filters/runtime-shader/ This is a technic we use in the latest Skia tutorial: https://www.youtube.com/watch?v=xNZCQvtnhIU Would that fit your use-case? Do you have an example from an app that exists in the real world that implements such feature? I would love to take a look |
Beta Was this translation helpful? Give feedback.
-
Thank you @wcandillonI am trying to implement a color picker like the image below I have been able to display the image and move the circular preview around with code below but i want to get the color of the pixel as you move the circular preview.
I really hope react-native-skia would help me implement this feature and I woud forever be grateful for your help. |
Beta Was this translation helpful? Give feedback.
-
I'm actually interested about the same functionality as @Teeeyyy. I have a color picker image on which user moves the finger around to see an eye-dropper kind of color circle. So practically something like I have it implemented on web as below: Screen.Recording.2023-05-12.at.11.47.32.mov |
Beta Was this translation helpful? Give feedback.
-
You can use the Magnifying Glass example: |
Beta Was this translation helpful? Give feedback.
-
Hi @wcandillon, I wonder how is this feature going? I have recently built an equivalent to Telegram's eye dropper feature under the color picker section however I can not get the color to JS side to use it somewhere else, I can get the color I want from the shader and display it at the most outer ring of the circular shape (the whole circle is a shader) but yeah I can not use it at all. I recently see a readPixels function in the image methods but I don't know if one can convert such pixels into colors. recording_20240629_200019.mp4 |
Beta Was this translation helpful? Give feedback.
-
Hi @Glazzes - Can you share your repo with this implementation? There appears to be a few libraries that can return the pixel color in an image at an x,y coordinate. Have you tried any of those? |
Beta Was this translation helpful? Give feedback.
-
Hi there, I've recently built an eyedropper using Skia and maybe you will find this as useful as I did, first you will need to take a snapshot of your canvas, once you get the image you may want to use const pixels = image.readPixels(x, y, {
colorType: ColorType.RGBA_F32,
alphaType: AlphaType.Premul,
height: 1,
width: 1,
});
console.log(pixels[0] * 255, pixels[1] * 255, pixels[2] * 255); Where x and y is the position relative to the top left corner of the image based on the image dimensions, not the ones rendered in the screen but the ones of the image object, use |
Beta Was this translation helpful? Give feedback.
-
@ajp8164 You can find my implementation here https://github.com/Glazzes/reanimated3-animations/tree/main/Telegram%20Color%20Picker/src/eyedropper |
Beta Was this translation helpful? Give feedback.
-
I need this to get color of a pixel on a on a group of two rectangle those have different gradients and blend mods.
Beta Was this translation helpful? Give feedback.
All reactions