简体   繁体   English

Web导出是否在处理图像?

[英]Web export in Processing with images?

This might be a obvious question but I haven't seen it addressed anywhere, but I'm trying to figure out why my web export of my Processing sketch is not retrieving saved images? 这可能是一个显而易见的问题,但是我没有看到它在任何地方都可以解决,但是我想弄清楚为什么我的Processing草图的Web导出没有检索保存的图像? I'm thinking I should package the image with the other files, but just dropping the image in the same folder doesn't seem to work. 我在想应该将图像与其他文件打包在一起,但是将图像放在同一文件夹中似乎不起作用。 I also know that I am exporting it correctly because when I export sketches without saved images (just shapes or text created within the program), it works just fine. 我也知道我正确地导出了它,因为当我导出不保存图像的草图(只是在程序中创建的形状或文本)时,它就可以正常工作。

Does anyone have any experience with this? 有人对这个有经验么? If this helps at all, the code is below (it's really very simple). 如果这完全有帮助,则下面的代码(它非常简单)。 Thank you! 谢谢!

draw.pde draw.pde

void setup () {
  size(1280,800);
  background(255,255,255);
}

void draw() {
  PImage img;
  img = loadImage("drake.png");
  image(img, mouseX, mouseY);
}

Processing's JavaScript mode uses asynchronous loading of images. 处理的JavaScript模式使用图像的异步加载。 That means that the image is loaded in the background, and it isn't loaded by the time you try to draw it. 这意味着图像已加载到背景中,并且在您尝试绘制图像时尚未加载。

A quick fix (which you should use anyway, even in Java mode) is to not load your images in the draw() function: you'll be reloading the same file 60 times per second! 一个快速的解决方法(即使在Java模式下,也应该使用该方法)是不将图像加载到draw()函数中:您每秒将重新加载同一文件60次! Instead, load it once at the start of the sketch. 而是在草图开始处加载一次。

Also, if you're using Processing.js, then you need the preload at the top. 另外,如果您正在使用Processing.js,则需要在顶部进行预加载。

/* @pjs preload="drake.png"; */

PImage img;

void setup () {
  size(1280,800);
  img = loadImage("drake.png");
  background(255,255,255);
}

void draw() {  
  image(img, mouseX, mouseY);
}

More info in the Processing.js reference here . 有关更多信息,请参见此处的Processing.js参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM