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.

How to render an image from React Native Image Picker

See original GitHub issue

Hello

I’m making an app which takes a picture from the phone’s camera, overlays the timestamp as text and a logo as watermark on the picture. And let’s the user store it on their phone.

I’m using react-native-image-picker to access the camera. I get the image and can display it using RN’s Image or ImageBackground components, but can’t seem to display it on the canvas.

Initial Canvas

_initCanvas = (canvas) => {
  let ctx = canvas.getContext('2d');
  canvas.width = 800;
  canvas.height = 1200;

  let image = new CanvasImage(canvas, 200, 200);
  image.src = this.state.image.path; 

  image.addEventListener('load', () => {
    ctx.fillStyle = 'purple';
    ctx.fillRect(0, 0, 100, 100);
    ctx.drawImage(image, 10, 10, 200, 200);
  });
}

Image Picker Response

image: {
  data: "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQ",
  fileName: "image-14a74c48-fcf3-4528-bdf1-b7c925acd293.jpg",
  fileSize: 133818,
  height: 600,
  isVertical: true,
  originalRotation: 0,
  path: "/storage/emulated/0/Android/data/com.image_watermark/files/Pictures/image-14a74c48-fcf3- 
  4528-bdf1-b7c925acd293.jpg",
  type: "image/jpeg",
  uri: "file:///storage/emulated/0/Android/data/com.image_watermark/files/Pictures/image-14a74c48- 
  fcf3-4528-bdf1-b7c925acd293.jpg", 
  width: 338,
}

Note The canvas is rendered after the response from react-native-image-picker is added to the state. I have tried ‘uri’, ‘path’ and ‘data’ attributes but always get a blank canvas. I do get the purple rectangle though.

End Result I want to be able to add the picture on canvas. Then add a logo and text over the picture and save it to my mobiles camera roll.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
iddancommented, Sep 27, 2018

@hzburki there is no progress to be made, it’s a use case needed to be figured out not a bug.

3reactions
hzburkicommented, Sep 26, 2018

Any progress ?? I’m kinda on a deadline ?? 😨

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pick images from Camera & Gallery in React Native ...
In this post, you learned how to implement React Native Image Picker in your React Native app and pick the images from Camera...
Read more >
An In-Depth Guide to Using React Native Image Picker
Enable your app to select an image from the user's camera or photo gallery with the React Native community module react-native-image-picker.
Read more >
React Native Pick Images From Camera & Gallery Example
Picking images is an essential task, learn how to pick images from the device's Camera and Gallery in React Native application.
Read more >
How to Use React-Native-Image-Picker | by Gapur Kassym
The basic idea is to build an image picker component that will allow the user to upload a new photo from the device's...
Read more >
Example of Image Picker in React Native
react -native-image-picker library provided an ImagePicker component in which you can set the options like the title of the picker, Your custom Buttons(Name...
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