Following code (from images on imgur) in fillPatternImage works:
var url = "http://www.imgur....."
var newImage = new window.Image();
newImage.src = url;
then I find ref to the shape I want to change and I use setAttr("fillPatternImage", image)
and it the pattern shows in my shape
But when I do:
<input type="file" ...blah blah ... onClick={(event) => {
var url = URL.createObjectURL(event.target.files[0];
let newImage = new window.Image()
newImage.src = url
}}
and then do the whole setAttr
thing, it wouldn't work. I am sure the source is valid in that if I make a new state called imageUrl with url from the uploaded image and do: <img src={this.state.imageUrl}
, the image shows perfectly.
Only difference between the 2 srcs:
- source from the direct imgur source is just the link to the image, for example: https://i.stack.imgur.com/EPxZX.png
- source from the uploaded image is "blob:http://localhost:3000/c0e5194d-1c58-4aa1-b4d6-6abf7438e179"
By the way, importing image file from the public folder and then setting it as the src of a native javascript image then fillPatternImage with that image also worked.