BlendColor. How to ignore transparent pixels with hue blend mode? #856
-
Hi and thanks for this place to ask questions. I wanted to replicate a simple example of flutter's const {width, height} = Dimensions.get('window');
const Example = () => {
const image = useImage(
'https://raw.githubusercontent.com/vijayinyoutube/colorfilterapp/master/assets/Images/product.png',
);
if (!image) {
return null;
}
return (
<View style={{flex: 1}}>
<Canvas style={{flex: 1}}>
<Fill color={'#000'} />
<Image
image={image}
x={0}
y={0}
fit={'contain'}
width={width}
height={width}>
<BlendColor color={'lightgreen'} mode={'hue'} />
</Image>
</Canvas>
</View>
);
}; |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
This looks interesting. What seems to be the issue with the example? Sorry I didn't get it 🙈 |
Beta Was this translation helpful? Give feedback.
-
I manage to get to it work by doing the following (but I'm cheating here): const { width } = Dimensions.get("window");
const Example = () => {
const image = useImage(
"https://raw.githubusercontent.com/vijayinyoutube/colorfilterapp/master/assets/Images/product.png"
);
if (!image) {
return null;
}
return (
<View style={{ flex: 1 }}>
<Canvas style={{ flex: 1 }}>
<Fill color={"#000"} />
<Group>
<Image
image={image}
x={0}
y={0}
fit={"contain"}
width={width}
height={width}
/>
<Group blendMode="hue">
<Fill color="lightgreen" />
</Group>
</Group>
</Canvas>
</View>
);
}; It works because it is black, but if you switch the background color you will see the hue is changed. I'm think you should just clip the result using the original image (blendmode="dstATop" ?). I'm not super famillar with blend modes yet. But this is a super cool example and I will add this example to the test suite. Also you might be interested into to use a shader with the image as an input programatically update the image as you want: https://shopify.github.io/react-native-skia/docs/shaders/overview#nested-shaders I hope this helps. |
Beta Was this translation helpful? Give feedback.
-
I added examples here I think you will be please about: https://github.com/Shopify/react-native-skia/blob/c029cdcf8403f2869c4c3cc560ef126fb2b1ed9f/package/src/renderer/__tests__/examples/BlendModes.spec.tsx |
Beta Was this translation helpful? Give feedback.
I added examples here I think you will be please about: https://github.com/Shopify/react-native-skia/blob/c029cdcf8403f2869c4c3cc560ef126fb2b1ed9f/package/src/renderer/__tests__/examples/BlendModes.spec.tsx
I think the shader approach would be the recommended approach.