Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Draw on image #112

Open
mymaichy opened this issue Jan 17, 2020 · 1 comment
Open

Draw on image #112

mymaichy opened this issue Jan 17, 2020 · 1 comment

Comments

@mymaichy
Copy link

Helllo,

I would like to use ExpoPixi.Sketch component to be able to draw on existing picture. I can drawing but image that I would like to use as a background don't show on my screen, please help me.

my code

import Expo from 'expo';
import * as ExpoPixi from 'expo-pixi';
import React, { Component } from 'react';
import { Image, StyleSheet, View, ImageBackground, background } from 'react-native';

export default class App extends Component {
state = {
image: null,
strokeColor: 20,
strokeWidth: 0x000000,
};

onChangeAsync = async ({ width, height }) => {
const options = {
format: 'png',
quality: 0.1,
result: 'file',
height,
width,
};
const uri = await Expo.takeSnapshotAsync(this.sketch, options);
this.setState({
image: { uri },
strokeWidth: 20,
strokeColor: 0x000000,
});

};

onReady = () => {
console.log('ready!');
};

render() {
console.disableYellowBox = true;
return (

    <ExpoPixi.Sketch
      ref={ref => (this.sketch = ref)}
      style={styles.sketch}
      strokeColor={this.state.strokeColor}
      onChange={this.onChangeAsync}
      onReady={async context => {

        const { uri } = this.state
        const renderer = this.sketch.renderer
        const stage = this.sketch.stage

        if (stage.children.length > 0) {
          stage.removeChildren()
          renderer._update()
        }

        var background = await PIXI.sprite.from(require('./assets/2.png'));

        stage.addChild(background);
        renderer._update();
      }}
      transparent={false}
    />

  </View>
);

}
}

Thanks a lot

@Shadowown
Copy link

Good day mymaichy.

Did you come right with this?
I'm also stuck on this at the moment.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants