首页 > 解决方案 > 在 LocalStorage 中保存草图线

问题描述

对不起,我把这个贴在这里

我想保存我在画布上绘制的每一行的信息(保存操作将被称为 onChange),以便我可以检索此数据并再次将其绘制在画布上,以防用户更改屏幕或其他内容。

我正在使用 expo-pixi 绘制图像并在其上绘制草图

onChangeAsync = async (param) => {
// here i want on change code i get the line informantion and store it

}
onLayout = async ({
        nativeEvent: {
            layout: { width, height },
        },
    }) => {
        this.setState({
            layoutWidth: width,
            layoutHeight: height,
        })
        this.onReady();
    }
onReady = async () => {
        const { layoutWidth, layoutHeight, points } = this.state;
        this.sketch.graphics = new PIXI.Graphics();

        if (this.sketch.stage) {

            if (layoutWidth && layoutHeight) {
                const background = await PIXI.Sprite.fromExpoAsync(this.props.image);
                background.width = layoutWidth * scaleR;
                background.height = layoutHeight * scaleR;

                this.sketch.stage.addChild(background);
                this.sketch.renderer._update();
            }
        }
    };

// The sketch component is pretty much as the example which comes with the lib
<Sketch
 ref={ref => (this.sketch = ref)}
 style={styles.sketch}
 strokeColor={this.state.strokeColor}
 strokeWidth={this.state.strokeWidth}
 strokeAlpha={1}
 onChange={this.onChangeAsync}
 onReady={this.onReady}
/>

有没有人有任何线索?我有点绝望

谢谢

标签: react-nativeexpo

解决方案


推荐阅读