Skip to content

Instantly share code, notes, and snippets.

@Akifcan
Created December 24, 2023 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akifcan/618cfa0f2cd7a81c80761d2d7562956b to your computer and use it in GitHub Desktop.
Save Akifcan/618cfa0f2cd7a81c80761d2d7562956b to your computer and use it in GitHub Desktop.
react-native-image-color-pick
const script = `
<script>
function get_average_rgb(img) {
var context = document.createElement('canvas').getContext('2d');
var src = img;
img = new Image;
img.setAttribute('crossOrigin', '');
img.src = "data:image/png;base64," + src;
img.onload = function () {
context.imageSmoothingEnabled = true;
context.drawImage(img, 0, 0, 1, 1);
const i = context.getImageData(0, 0, 1, 1).data;
const rgba = "rgba(" + i[0] + ',' + i[1] + ',' + [2] + ")"
console.log(rgba)
const HEX = "#" + ((1 << 24) + (i[0] << 16) + (i[1] << 8) + i[2]).toString(16).slice(1);
window.ReactNativeWebView.postMessage(HEX);
}
}
get_average_rgb('${base64}')
</script>
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment