User Tools

Site Tools


issues_with_loadimage

Old Problems/Solutions with loadImage in Linux

See Reports for updated info.

In Basic mode:

The following example loads a picture from processing.org. It then takes the pixel[] array and sets every pixel (except the loaded picture) to be pink. If you click the “run” button, you won't see anything. If you go to “Sketch” → “Present”, you'll see the image. In both cases, you'll see the output “500,000 pixels” (500×1000 window).

//Example 1: works with Present, not with Run...
size(1000,500);
PImage b = loadImage("http://processing.org/img/processing_beta_cover.gif");
loadPixels();
color pink = color(255, 102, 204);
loadPixels();
System.out.println(pixels.length + " pixels");
for (int i=0; i<pixels.length; i++) {
  pixels[i] = pink;
}
updatePixels();
image(b,50,50);
In Continuous mode:

Same thing, but this time you'll notice that it works with both Run (you may have to move the window) and Present. The output is now “502,000 pixels”, even though the image size has not been changed.

//Example 2: works in both
void setup()
{
  size(1000,500);
}
void draw()
{
  PImage b = loadImage("http://processing.org/img/processing_beta_cover.gif");
  color pink = color(255, 102, 204);
  loadPixels();
  System.out.println(pixels.length + " pixels");
  for (int i=0; i<pixels.length; i++) {
    pixels[i] = pink; 
  }
  updatePixels();
  image(b,50,50);
}

-I think that the extra 2,000 pixels are a kind of buffer that's created in Continuos mode, but not in Basic mode, that ensures that the image doesn't overflow within the window. 2,000 pixels is a 1 pixel horizontal buffer on the top/bottom. This doesn't seem to be the case: even when you manually put a 50 pixel buffer around all edges, waiting is still necessary. Check bug report #282 for a possible solution.

Solution

Immediately after size():

int waitingTime = 50;
  try{
    wait(waitingTime);
  }catch(Exception e){}

This seems to solve the problem. Output is now “502,000 pixels”.

If the size of your window was based on the size of the image, you had to wait even longer (250-ish or more) with Java2D:

size(Image.width, Image.height);
try{
  wait(250);
}catch(Exception e) {System.out.println(e);}
issues_with_loadimage.txt · Last modified: 2007/08/30 13:53 (external edit)