Closed lilian-delouvy closed 4 weeks ago
Found the solution.
It seems like the library has trouble with local images. There are plenty examples of this library using distant images (take a look at the "example/app/index.tsx" file), but none with local images. Turns out, using
const img = new CanvasImage(canvas);
const imageUri = RNimage.resolveAssetSource(resolveImage()).uri;
img.src = imageUri;
does not work. What works instead, is to encode the image in base64, then doing this:
const image = new CanvasImage(canvas);
image.src = ""data:image/png;base64,<YOUR_BASE_64_HERE>"
image.addEventListener("load", () => {
ctx.drawImage(image, 0, 0, 100, 100); // dimensions are here only as an example
});
I feel like there is a lack of documentation here / lack of example, as I saw quite a lot of people banging their heads with this. I'll try to provide a PR to display this, but will close this issue for now.
Hello,
I'm trying to create a component to do 9-patch scaling of an image.
The emulator shows the image properly, but creating a release apk and using it on a real device does not show the canvas.
There is no logged error, nothing, as if it worked properly.
Is there something I'm missing here ? I'm fairly new to react-native, so that might be the case.
I already took a look in the examples folder you provide, but none of the examples display usage of a local image. I'm wondering if there is a bug with the local image handling