expo-pixi icon indicating copy to clipboard operation
expo-pixi copied to clipboard

Error: Expected URL scheme 'http' or 'https' but was 'file'

Open linus opened this issue 4 years ago • 2 comments

I'm trying to use expo-pixi to read out the color of the background (really the top left pixel) of an image. The image is hosted on a https:// url.

I'm doing this:

  async getBackgroundColor(imageUri) {
    const context = await GLView.createContextAsync()
    const app = new PIXI.Application({ context })
    console.log('[PIXI] loading', imageUri)
    const sprite = await PIXI.Sprite.fromExpoAsync(imageUri)
    console.log('[PIXI] sprite', sprite)
    app.stage.addChild(sprite)
    const pixels = app.renderer.extract.pixels(sprite)
    console.log('[PIXI] extracted pixels', pixels.length)
    const [r, g, b, a] = pixels.slice(0, 4)
    console.log('[PIXI] loaded pixels', [r, g, b, a])

    return `rgba(${r}, ${g}, ${b}, ${a})`
  }

Unfortunately, the call PIXI.Sprite.fromExpoAsync(imageUri) throws an error:

Error: Expected URL scheme 'http' or 'https' but was 'file'

I have looked through the documentation as well as reading through the issues and some of the code, it seems as if the exception comes from a lower level, but how is fromExpoAsync supposed to be used? Is it possible to use remote resources? Should I use another API?

See this snack: https://snack.expo.io/@fredrikschweinebarth/8ac094

linus avatar Oct 14 '19 13:10 linus

It seems as if this is because of a bug in expo-asset-utils: https://github.com/expo/expo-asset-utils/issues/18

linus avatar Oct 14 '19 14:10 linus

Have you managed to solve this problem? I had the same issue when loading a texture from remote url.

LeonYuanYao avatar Feb 26 '20 02:02 LeonYuanYao