Question

So, I'm trying to crop and show a picture, and I want the picture shown to be as large as the screen each time, and so far I have this piece of code, but the image size changes each time, and according to the API it should be full screen?

PImage img;
PImage temp;

void setup() {
  size(800, 600);
  img = loadImage("genevieve-bjargardottir1.jpg");
  frameRate(5);
}

void draw() {
  background(0);
  text(frameRate, 10, 20);

  int x, y, xx, yy;
  x = (int)random(width);
  xx = (int)random(width);
  y = (int)random(height);
  yy = (int)random(height);

  temp = img.get(x, y, xx, yy);

  image(temp, 0, 0, width, height);

}

I thought that the last line:

image(temp, 0, 0, width, height);

would display my cropped image to the whole window. Starting points are set to 0 0, and end points to width and height of the current window size.

Was it helpful?

Solution

reading @Kevin Workman's advice I came up with the following snippet :)

PImage img;
PImage temp;
float prop;

void setup() {  
  while ( img == null) {
    img = loadImage("http://xaxor.com/images/Genevieve-Bjargardottir/Genevieve-Bjargardottir1.jpg");
  }

  prop =  (float)img.width / (float)img.height ;

  size(800, int(800/prop));

  frameRate(1);
}


void draw() {

  float pw = random(img.width);
  float ph = pw / prop;


  int x, y;
  x = int(random(img.width - pw));
  y = int(random(img.height - ph));

  // scaled piece
  temp = img.get(x, y, int(pw), int(ph));
  image(temp, 0, 0, width, height);

  //full pict
  image(img, 0, 0, img.width/6, img.height/6);
  noFill();
  stroke(255);

  //croped piece
  rect(x/6, y/6, pw/6, ph/6);
}

OTHER TIPS

You're getting a random part of the image each frame (5 times a second), and then displaying that part of the image the full size of the window. What did you expect to happen?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top