# 'img cannot be resolved to a variable'

**URL:** <https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431>\
**Category:** Libraries\
**Created:** [December 15, 2019, 10:17pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431 "2019-12-15T22:17:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Louis](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Louis](https://discourse.processing.org/u/Louis)\
**Post date:** [December 15, 2019, 10:17pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/1 "2019-12-15T22:17:46Z")

</div>

I’m trying to create a script that will print image frames by interval,

current code:

```auto
int xpos = 0;
int ypos = 0;
int VWIDTH = 8; // width of capture
int VHEIGHT = 6; // height of capture
int MOVIEWIDTH = VWIDTH * 60; // width is equivalent to 1 minute of film time
int MOVIEHEIGHT = VHEIGHT * 130; // 130 minutes
int MAXWIDTH = MOVIEWIDTH - VWIDTH;
int MAXHEIGHT = MOVIEHEIGHT - VHEIGHT;
boolean capture = false;
boolean newFrame = false;

void setup()
{
  surface.setSize(MOVIEWIDTH, MOVIEHEIGHT);
  background(0);
}

void mousePressed() {
  // click screen to start capture
  // click again to take screengrab if required
  if (capture == false) {
    capture = true;
  } 
  else {
    saveFrame();
  }

}

void videoEvent()
{
  newFrame = true;
}

void loop()
{
  if(newFrame && capture==true) {

    image(img,xpos, ypos);
    xpos += VWIDTH;
    if (xpos > MAXWIDTH) {
      xpos = 0;
      ypos += VHEIGHT;
    }
    if (ypos > MAXHEIGHT) {
      saveFrame();
      ypos = 0;
      background(0);
    }
    newFrame = false;
  }
}

```

any fix suggestions welcome!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 15, 2019, 10:20pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/2 "2019-12-15T22:20:44Z")

</div>

> [@Louis](#):
>
> image(img,xpos, ypos);

Maybe you forgot to say PImage img; previous to setup() or to load img in setup with loadImage()

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 15, 2019, 10:21pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/3 "2019-12-15T22:21:39Z")

</div>

> [@Louis](#):
>
> void loop()

loop or draw() is it?

What language?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 16, 2019, 2:20am UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/4 "2019-12-16T02:20:06Z")

</div>

please format your code posting by pasting it into the

```auto
</> code button

```

of the editor header menu ( context name: Preformatted text )  
it looks like  
```  
type or paste code here  
```

also can use the ``` manually above and below your code.

thank you.

* * *

for start using ( the video ) lib stay close to the examples  
[https://processing.org/reference/libraries/video/Capture.html](https://processing.org/reference/libraries/video/Capture.html)

---

<div class="post-metadata">

**Author:** ![Louis](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Louis](https://discourse.processing.org/u/Louis)\
**Post date:** [December 16, 2019, 1:18pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/5 "2019-12-16T13:18:32Z")

</div>

Hi sorry, very new to programming, so I’m trying to create a script that captures frames of a video and arranges them on a grid (60x130)

```auto
int xpos = 0;
int ypos = 0;
int VWIDTH = 8; // width of capture
int VHEIGHT = 6; // height of capture
int MOVIEWIDTH = VWIDTH * 60; // width is equivalent to 1 minute of film time
int MOVIEHEIGHT = VHEIGHT * 130; // 130 minutes
int MAXWIDTH = MOVIEWIDTH - VWIDTH;
int MAXHEIGHT = MOVIEHEIGHT - VHEIGHT;
boolean capture = false;
boolean newFrame = false;

void setup()
{
  surface.setSize(MOVIEWIDTH, MOVIEHEIGHT);
  background(0);
}

void mousePressed() {
  // click screen to start capture
  // click again to take screengrab if required
  if (capture == false) {
    capture = true;
  } 
  else {
    saveFrame();
  }

}

void videoEvent()
{
  newFrame = true;
}

void loop()
{
  if(newFrame && capture==true) {

    image(img,xpos, ypos);
    xpos += VWIDTH;
    if (xpos > MAXWIDTH) {
      xpos = 0;
      ypos += VHEIGHT;
    }
    if (ypos > MAXHEIGHT) {
      saveFrame();
      ypos = 0;
      background(0);
    }
    newFrame = false;
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 16, 2019, 1:33pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/6 "2019-12-16T13:33:55Z")

</div>

processing JAVA does not know capture or videoEvent

but you can  
after install processing 3.5.3  
install a video library via contribution manager  
PDE / Tools / Add Tool /  
Libraries / Video /

```auto
Video 1.0.1 The Processing Foundation GStreamer-based video library for Processing.

```

after that might need restart processing IDE  
find:  
PDE / File / Examples / Libraries / Video / Movies / Frame /

using

```auto
import processing.video.*;

```

a example what play a existing video file and show next frame on [-\>]

if that is not what you want, please try again to describe what you want to do.  
but above you say:

> [@Louis](#):
>
> a script that captures frames of a video

* * *

while in the first post you say

> [@Louis](#):
>
> I’m trying to create a script that will print image frames by interval,

for that ignore all the video things and just use

> **[saveFrame() / Reference](https://processing.org/reference/saveFrame_.html)**
>
> Saves a numbered sequence of images, one image each time the function is run. To save an image that is identical to the display window, run the function at the end of draw() or within mouse and…

and start from example:  
PDE / File / Examples / Topics / File IO / SaveFrames

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 16, 2019, 1:43pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/7 "2019-12-16T13:43:13Z")

</div>

Isn’t it void draw and not void loop in the first place?

---

<div class="post-metadata">

**Author:** ![Louis](https://avatars.discourse-cdn.com/v4/letter/l/ecb155/32.png) [@Louis](https://discourse.processing.org/u/Louis)\
**Post date:** [December 16, 2019, 10:17pm UTC](https://discourse.processing.org/t/img-cannot-be-resolved-to-a-variable/16431/8 "2019-12-16T22:17:06Z")

</div>

This is perfect, thanks!
