Created
December 24, 2023 21:04
-
-
Save Akifcan/618cfa0f2cd7a81c80761d2d7562956b to your computer and use it in GitHub Desktop.
react-native-image-color-pick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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