-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to draw local image on canvas using react-native-canvas #60
Comments
I would use React Native FS: import RNFS from 'react-native-fs';
const imageSrc = `${RNFS.MainBundlePath}/${FILE_PATH}` |
Thank you iddan. Sincerely, |
Hey @zokicpokic, were you able to solve this problem? |
Hi @iddan , thank you for asking. I was able to solve this by
Then: I am using create react native app and Expo, linking FS appeared not easy going approach since linking and Expo are not much compatible. But I will keep using react-native-canvas since it is most straightforward and achievable for 2D rendering. Thank you once again. |
I think once an image is loaded you can utilise it in the same canvas. |
Thanks for this. Without Expo, you can solve it using "resolveAssetSource" like this:
and then:
Note that resolveAssetSource is method from React Native Image, so you need to import is also, but with a different name. |
For those struggling to import PNGs in typescript
|
RNimage.resolveAssetSource It doesn't work on the release |
${RNFS.MainBundlePath} Output undefined on Android |
@zokicpokic solution works just fine, thanks! import {Asset} from 'expo-asset'
import {Image as CanvasImage} from 'react-native-canvas'
async loadImage(localPath: string): Promise<CanvasImage> {
const i = new CanvasImage(canvas)
const asset = Asset.fromModule(require(localPath))
i.src = asset.uri
return await new Promise(r => {
i.addEventListener('load', () => {
r(i)
})
})
} |
might as well save what I have so far also removed some stuff that we will want to add back [react native canvas drawing](iddan/react-native-canvas#60) [react native canvas](https://github.com/iddan/react-native-canvas)
Hi,
Thank you for the package.
I have followed instructions in the source and I am not able to draw image on canvas if image's source is within a project.
here is the code:
Is it possible to set image.src to local path?
Thank you once again.
Regards,
Zoran
The text was updated successfully, but these errors were encountered: