We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I need some help with:
loadImage() from createImg()-p5.dom
or
loadImage() from a data URI, such as "data:image/jpg;base64,{base 64 encoded data block}"
The createImg() comes from an createFileInput(), and I want o be able to resize() that image.
Thanks for your help!
Code below:
function setup() {
createFileInput (handleFile);
createCanvas (800, 400);
background (245);
}
function draw() {
strokeWeight (10);
stroke (0, 255,0);
line (pmouseX, pmouseY, mouseX, mouseY);
}
function handleFile (file) {
if (file.type === 'image') {
var img = createImg (file.data).hide();
print (img);
//img.resize (width, 0);
image (img, 0, 0);
}
}
Answers
https://p5js.org/reference/#/p5.Element/size
Another approach is to replace createImg() w/ loadImage(): *-:)
http://p5js.SketchPad.cc/sp/pad/view/ro.CYTkHWj9smgw8Q/latest
@GoToLoop Can you explain what
evt.preventDefault();
does in your post?I can see this in the reference: https://p5js.org/reference/#/p5/mouseReleased
Kf
https://Developer.Mozilla.org/en-US/docs/Web/API/Event/preventDefault
That trick only works for the global events. :ar!
For p5.Element's, an explicit call to preventDefault() is needed. L-)
@GoToLoop Thxs.
Kf
@GoToLoop Thanks!