HTML - loadImage NOT in setup()
in
Processing with Other Languages
•
1 month ago
Hi all,
I'm new here, I hope you can help me, and I hope that I'm posting my problem in the good forum.
I'm working on a small application, the idea is to use it in a web page. I use the "processing-1.4.1.js" core file.
Here is my code:
As you can see, I I pre-loads a local JPG file in the SETUP block, it works great.
Now, my goal is to load the picture in the DRAW block, as the file name will vary. And as the file name can vary a lot, I can't preload all the images in an array. but If i put the
img = loadImage( "file://C:/Users/TRAVAIL/Documents/Processing/animation_pleurant/H1/render_0001.png");
in the DRAW function, the image is not loaded, and the screen stays black...
To sum up, my goal is to use the loadImage function in the DRAW function, not in SETUP...
I hope that you understand my problem !
Thanks in advance.
Best regards,
Benjamin
I'm new here, I hope you can help me, and I hope that I'm posting my problem in the good forum.
I'm working on a small application, the idea is to use it in a web page. I use the "processing-1.4.1.js" core file.
Here is my code:
- <html>
<head>
<title>Image seule</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="example"><script type="application/processing">
PImage img; // variable specfique pour chargement image
boolean Refresh;
void setup()
{
size(480, 640);
frameRate(10);
// noCursor();
Refresh =true;
imageMode(CENTER); //pour affichage image
img = loadImage( "file://C:/Users/TRAVAIL/Documents/Processing/animation_pleurant/H1/render_0001.png"); //charge nouvelle image
}
//boucle principale
void draw() {
if (Refresh) {
background(0); //efface l'écran
// img = loadImage( "file://C:/Users/TRAVAIL/Documents/Processing/animation_pleurant/H1/render_0001.png"); //charge nouvelle image
image(img, 640/2, 480/2, 640, 480); //affiche la nouvelle image, a priori au bon endroit
fill(255);
text("test",10,10);
Refresh = false;
}
}
</script><canvas width="640" height="480"></canvas>
<script src="processing-1.4.1.js" type="text/javascript"></script>
</body>
</html>
As you can see, I I pre-loads a local JPG file in the SETUP block, it works great.
Now, my goal is to load the picture in the DRAW block, as the file name will vary. And as the file name can vary a lot, I can't preload all the images in an array. but If i put the
img = loadImage( "file://C:/Users/TRAVAIL/Documents/Processing/animation_pleurant/H1/render_0001.png");
in the DRAW function, the image is not loaded, and the screen stays black...
To sum up, my goal is to use the loadImage function in the DRAW function, not in SETUP...
I hope that you understand my problem !
Thanks in advance.
Best regards,
Benjamin
1