Ask user for image

I want to ask the user for an image and then have the sketch show the image with the window of the same size(Resizing will not work because I want to manipulate it at the pixel level). This is broken in the new processing 4.0a2 because you can no longer load image in settings so I am wondering how can I do this now? I know I am not the only person to have this problem.

Hi @x13420x,

I have tested this and I guess it works.
Try it out. Not sure if this is what you are looking for. Hope it helps :slight_smile:

ps: I am using processing 3.5.3

PImage img;
boolean imgSelected = false;
void setup() {
  size(100, 100);
  surface.setResizable(true);
  selectInput("Select a file to process:", "fileSelected");
}

void draw() {
  if (imgSelected) {
    image(img, 0, 0);
  }
}

void fileSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
    String path =  selection.getAbsolutePath();
    String breakpath[] = split(path, "\\");
    String filename = breakpath[breakpath.length - 1];
    println(filename);

    img = loadImage(filename);
    println("w = " + img.width +"\t h = " + img.height);
    surface.setSize(img.width, img.height);
    imgSelected = true;
  }
}

Best regards

1 Like

This code is broken in processing 4…but I did try your method and it didnt work becuase I want to manipulate the image at the pixel level. Basically I want the image to start off with the digits of pi…example first pixel RGB(contains first 3 digits of pi in base 256)…well doing your method just shows a black image…unless I start with the real size parameters…if I start off with size(100,100) then I get out of cordinates error(null pointer exception)…Yeah basically I think there is no simple way of doing this…but Ben Fry doesnt see the problem.

Thanks for trying to help…I think I need a more advanced solution

In my case, the code works, but since you are trying to manipulate pixels, I would suggest you look the following links.

Pixel manipulation links

https://processing.org/reference/loadPixels_.html
https://processing.org/reference/pixels.html
https://processing.org/reference/updatePixels_.html

Here you can find how to load Images, and manipulate pixels as well. I believe this should help you get on the right track at least.

Best regards

Yeah but if you resize the window like you showed then it breaks all the pixel manipulation…cause it is based on the original size