Draw local image on canvas using react-native-canvas

44 views Asked by At

everyone. I am going to draw image in expo react native project. Btw it is working on development stage with "yarn start", but after building the apk, image isn't displaying on canvas. Please check below codebase and let me know. If anyone has experience in this kind of issue, please let me know the solution for this. Thank you.

import {Asset} from 'expo-asset';


const context = canvas.getContext(`2d`);
let img = new CanvasImage(canvas);
img.src = Asset.fromModule(require(`../assets/images/gameIcons/game.png`)).uri;

img.addEventListener('load', function() {
    context.drawImage(image, 0, 0, 100, 100);
})
1

There are 1 answers

0
Timeworn On BEST ANSWER

I had some research to solve this issue for some days, finally I found the solution for this. I convert all images into base64 image from online converter, and inputed that base64 image into src of img tag. Finally solved from this way.

img.src = base64Image