GithubHelp home page GithubHelp logo

Comments (6)

philvoyer avatar philvoyer commented on June 7, 2024 1

I finally succeeded to draw a local image file with this modified version of the basic example:

import React from 'react';
import Expo from 'expo';
import { GLView } from 'expo-gl';
import { PIXI } from 'expo-pixi';

export default () => (
    <GLView
      style={{ flex: 1 }}
      onContextCreate={async context => {
        const app = new PIXI.Application({ context });
        const sprite = await PIXI.Sprite.fromExpoAsync(require('./assets/img.png'));
        app.stage.addChild(sprite);
    }}
    />
);

from expo-pixi.

basaksilasanli avatar basaksilasanli commented on June 7, 2024

Same issue!!

from expo-pixi.

rafipiccolo avatar rafipiccolo commented on June 7, 2024

I just adapted the imports
and did those installs :

expo install expo-gl
expo install expo-pixi

App.js

import React, { Component } from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import Constants from 'expo-constants';
import * as FileSystem from 'expo-file-system';
import base64 from 'base64-js';
import ExpoPixi from 'expo-pixi'; 

export default class App extends Component {
  constructor(props) {
    super(props);
    this.sketch = null;
  }

  stringToUint8Array(str) {
    const length = str.length;
    const array = new Uint8Array(new ArrayBuffer(length));
    for (let i = 0; i < length; i++) array[i] = str.charCodeAt(i);
    return array;
  }

  async fileToBase64(uri) {
    try {
      const content = await FileSystem.readAsStringAsync(uri);
      return base64.fromByteArray(this.stringToUint8Array(content));
    } catch (e) {
      console.warn('fileToBase64()', e.message);
      return '';
    }
  }

  fileToBase64Helper(uri) {
    return this.fileToBase64(uri);
  }

  render() {
    const color = 0x000000;
    const width = 4;
    const alpha = 1;
    return (
      <View style={{ flex: 1 }}>
        <ExpoPixi.Signature
          ref={ref => (this.sketch = ref)}
          strokeColor={color}
          strokeWidth={width}
          strokeAlpha={alpha}
          style={{ flex: 1 }}
          onChange={async () => {
            const { uri } = await this.sketch.takeSnapshotAsync({
              format: 'png',
            });
            // console.log(await this.fileToBase64Helper(uri))
            console.log(uri);
            try {
              const file = await FileSystem.readAsStringAsync(uri, {
                encoding: 'base64',
              });
              console.log(file);
            } catch (e) {
              console.error(e.message);
            }
          }}
        />
        <View
          style={{
            height: 80,
            alignItems: 'center',
            justifyContent: 'space-between',
            flexDirection: 'row',
            paddingHorizontal: 20,
          }}>
          <TouchableOpacity
            style={{
              backgroundColor: 'white',
              height: 50,
              justifyContent: 'center',
              alignItems: 'center',
              width: '45%',
              borderRadius: 6,
              borderColor: '#0d52bd',
              borderWidth: 2,
            }}>
            <Text style={{ fontSize: 19, color: 'black' }}>Cancel</Text>
          </TouchableOpacity>
          <TouchableOpacity
            style={{
              backgroundColor: '#0d52bd',
              height: 50,
              justifyContent: 'center',
              alignItems: 'center',
              width: '45%',
              borderRadius: 6,
            }}>
            <Text style={{ fontSize: 19, color: 'white' }}>Save</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  }
}

from expo-pixi.

philvoyer avatar philvoyer commented on June 7, 2024

Thanks @rafipiccolo for your answer,

Your 'Signature' example is working for me.

But, are you able to execute this code that use a GLView :

import React from 'react';
import Expo from 'expo';
import { ExpoPixi } from 'expo-pixi';

export default () => (
  <Expo.GLView
    style={{ flex: 1 }}
    onContextCreate={async context => {
      const app = new ExpoPixi.Application({ context });
      const sprite = await ExpoPixi.Sprite.fromExpoAsync(
        'http://i.imgur.com/uwrbErh.png',
      );
      app.stage.addChild(sprite);
    }}
  />
);

This is the same code as the example from https://github.com/expo/expo-pixi, but with "PIXI" swapped with "ExpoPixi".

from expo-pixi.

philvoyer avatar philvoyer commented on June 7, 2024

I have also tried this:

import React from 'react';
import Expo from 'expo';
import { GLView } from 'expo-gl';
import { ExpoPixi } from 'expo-pixi';

export default () => (
  <GLView
    style={{ flex: 1 }}
    onContextCreate={async context => {
      const app = new ExpoPixi.Application({ context });
      const sprite = await ExpoPixi.Sprite.fromExpoAsync(
        'http://i.imgur.com/uwrbErh.png',
      );
      app.stage.addChild(sprite);
    }}
  />
);

In this case, no TypeError: undefined is not an object (evaluating '_expo.default.GLView) error, but a Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'new _expoPixi.ExpoPixi.Application') warning instead and a white screen with no image.

from expo-pixi.

rafipiccolo avatar rafipiccolo commented on June 7, 2024

hello,

this one would work if it wasn't for this other bug wich prevent loading https files : #103

although It may work with http or local file. I'm pretty lazy now as i dont know how to test it.

:) 👍

import { PIXI } from 'expo-pixi';
import React from 'react';

export default () => (
  <GLView
    style={{ flexGrow: 1, flexShrink: 0, flexBasis: 'auto' }}
    onContextCreate={async context => {
      const app = new PIXI.Application({ context });
      // const texture = await PIXI.Texture.fromExpoAsync('http://i.imgur.com/uwrbErh.png');
      // const texture = await PIXI.Texture.from('http://i.imgur.com/uwrbErh.png');
      // const sprite = PIXI.Sprite.from(texture);
      // const sprite = await PIXI.Sprite.from('http://i.imgur.com/uwrbErh.png');
      const sprite = await PIXI.Sprite.fromExpoAsync('https://i.imgur.com/uwrbErh.png');
      app.stage.addChild(sprite);
    }}
  />
);```

from expo-pixi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.