iddan / react-native-canvas

A Canvas component for React Native
MIT License
981 stars 172 forks source link

How to draw local image on canvas using react-native-canvas #327

Closed echofrost38 closed 5 months ago

echofrost38 commented 5 months ago

Hello,everyone. I am going to draw image in expo react native project. Btw it is working on development stage with "yarn start", but afte r 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); })

echofrost38 commented 5 months ago

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