# Ask user for image

**URL:** <https://discourse.processing.org/t/ask-user-for-image/25287>\
**Category:** Processing\
**Created:** [November 8, 2020, 9:08pm UTC](https://discourse.processing.org/t/ask-user-for-image/25287 "2020-11-08T21:08:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![x13420x](https://avatars.discourse-cdn.com/v4/letter/x/ecc23a/32.png) [@x13420x](https://discourse.processing.org/u/x13420x)\
**Post date:** [November 8, 2020, 9:08pm UTC](https://discourse.processing.org/t/ask-user-for-image/25287/1 "2020-11-08T21:08:31Z")

</div>

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.

> <https://github.com/processing/processing4/issues/150#issuecomment-723509361>
>
> worked fine in 4.0a1....there has been issues in the pást with this size(paint.width, paint.height) but the error is actually thrown one...

> <https://github.com/CodingTrain/Rainbow-Topics/issues/94>
>
> void settings() {
> selectInput("Please select random image:", "selectImage");
> interrupt();
> img = loadImage(input);
> size(img.width, img.height);
> noSmooth();
> } 
> docs say not to loadimage in...

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [November 9, 2020, 10:33am UTC](https://discourse.processing.org/t/ask-user-for-image/25287/2 "2020-11-09T10:33:35Z")

</div>

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 🙂

ps: I am using processing 3.5.3

```auto
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

---

<div class="post-metadata">

**Author:** ![x13420x](https://avatars.discourse-cdn.com/v4/letter/x/ecc23a/32.png) [@x13420x](https://discourse.processing.org/u/x13420x)\
**Post date:** [November 9, 2020, 4:59pm UTC](https://discourse.processing.org/t/ask-user-for-image/25287/3 "2020-11-09T16:59:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [November 10, 2020, 8:24am UTC](https://discourse.processing.org/t/ask-user-for-image/25287/4 "2020-11-10T08:24:43Z")

</div>

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/loadPixels_.html)  
> [https://processing.org/reference/pixels.html](https://processing.org/reference/pixels.html)  
> [https://processing.org/reference/updatePixels\_.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

---

<div class="post-metadata">

**Author:** ![x13420x](https://avatars.discourse-cdn.com/v4/letter/x/ecc23a/32.png) [@x13420x](https://discourse.processing.org/u/x13420x)\
**Post date:** [November 10, 2020, 4:46pm UTC](https://discourse.processing.org/t/ask-user-for-image/25287/5 "2020-11-10T16:46:40Z")

</div>

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
