question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cant get localSourceImage to load image from camera or gallery

See original GitHub issue

I just ejected from Expo in order to activate this module and I can get the vanilla sketchpad example to show up in the app. Im still using ExpoKit, Using the ExpoKit image picker, and Im using the IOS emulator. I can get an image URI from the gallery or I can snap a photo from the non existant camera (produces a black image).

If I get an image from the gallery the URI is in the format “file://really/long/path/to/file.jpg” If I get an image from tha camera the URI is in the format “asset-library://asset.jpg&id=someId”

I cant get either one of these URIs to load into the sketch canvas. The sketch canvas is still functional it just does not load the image.

I have not had a chance to get this on a physical device yet, my results are through the ios emulator. To me possible issues may be:

  • works on device but not emulator (havnt gotten it on a physical device yet)
  • maby the expoKit URIs are different then Native URIs so it cant find the image
  • my code is wrong

Any thoughts here?

Thanks, Michael

const srcImage = {
  filename: uriRetreivedFromCamera.jpg,
  directory: '', 
  mode: 'AspectFill'
}

Then somewhere in the JSX

<SketchCanvas
     style={{ flex: 1 }}
     strokeColor={'red'}
     strokeWidth={7}
     localSourceImage={srcImage}
 />

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

7reactions
bvodolacommented, Oct 8, 2018

@MichaelTaylor3D I was facing the same issue and maybe this will help:

Remove the file:// from your image URI retrieved from the camera:

uri.replace('file://', '')

If you take a look at the example code from this repo, https://github.com/terrylinla/react-native-sketch-canvas/blob/master/example/App.js#L37 he does exactly that.

3reactions
leonyhenncommented, May 25, 2019

@maverickVision

async _pickImage() {
    let result = await ImagePicker.launchImageLibraryAsync({base64:true});
    if (!result.cancelled) {
      base64 = result.base64
      extension =  result.uri.split('.').pop();
      
      decodedImage = decode(base64);
      // console.log(decodedImage)
      var path = DocDir + '/TempFile';
      new_filename = path+"/sample_image."+extension
      console.log(new_filename)
      //write the file
      RNFS.mkdir(path).then((success) => {
        RNFS.writeFile(new_filename, base64, 'base64').then((success) => {
            if(Platform.OS == 'ios'){
              this.setState({ photoPath: new_filename });
            }else{
              this.setState({ photoPath: new_filename });  
            }
          }).catch((err) => {
            console.log(err.message);
          });
      }).catch((err) => {
        console.log(err.message);
      });
    }
  };

that was what I had. and in the Sketch section:

<View style={{ flex: 1, flexDirection: 'row' }}>
              <RNSketchCanvas
                localSourceImage={{ filename: this.state.photoPath, directory: null, mode: 'AspectFit' }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

android - image load in imageview from camera or gallery
Try this Here imgPic is ImageView private void selectImage() { final CharSequence[] options = { "Take Photo", "Gallery" }; AlertDialog.
Read more >
How to pick images from Camera & Gallery in React Native app
We are going using a Native API Camera and choose the image from the Gallery. So, we need to provide some permission to...
Read more >
Flutter : Image Picker | Load image from the camera - YouTube
Your browser can't play this video. Learn more. Switch camera ... You will learn loading Image from the gallery, camera.
Read more >
Android Capture Image from Camera and Gallery - DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute ......
Read more >
Find lost photos and videos - Android - Google Support
If you use a different gallery, but tap 'Free up space' on Google Photos · Check if backup is on · Find an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found