# Copy from source to PGraphics

**URL:** <https://discourse.processing.org/t/copy-from-source-to-pgraphics/36958>\
**Category:** Libraries\
**Created:** [May 19, 2022, 8:58am UTC](https://discourse.processing.org/t/copy-from-source-to-pgraphics/36958 "2022-05-19T08:58:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luis\_Luethi1](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@Luis\_Luethi1](https://discourse.processing.org/u/Luis_Luethi1)\
**Post date:** [May 19, 2022, 8:58am UTC](https://discourse.processing.org/t/copy-from-source-to-pgraphics/36958/1 "2022-05-19T08:58:46Z")

</div>

Hello,  
I am working on a simple visualization from the slitscan process. I try to copy from an movie input into an PGraphics buffer. When I try it I get the following error when I try to copy in draw.

```auto
Width (0) and height (0) cannot be <= 0

```

Do you know how this happens?

Code

```auto
import processing.video.*;
PGraphics pg_draw;
PGraphics pg_video;
Movie Input;

int slice = 20;
int xpos = 1920/2;
PImage img;

void setup() {
  img = loadImage("014.png");
  size(1920, 1080);

  pg_draw = createGraphics(width/2, height);
  pg_video = createGraphics(width/2, height);
  Input = new Movie(this, "CBIR.mov");
  Input.play();
  Input.speed(100);
  Input.volume(0);
  background(0);
}

void draw(){
  if(Input.available()){
    Input.read();
  }
  
  //Video Buffer
  pg_video.beginDraw();
  pg_video.image(Input,0,0);
  pg_video.endDraw();
  
  //Slitscan Buffer
  pg_draw.beginDraw();
  int w = Input.width;
  int h = Input.height;
  copy(Input, w/2, 0, slice, h, pg_draw.width/2, 0, slice, h);
  pg_draw.endDraw();
  
  image(pg_video, 0, 0);
  image(pg_draw, width/2, 0);
  if (Input.time() == Input.duration()) { //movie must be finished
    exit();
  }
```

---

<div class="post-metadata">

**Author:** ![noahbuddy](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@noahbuddy](https://discourse.processing.org/u/noahbuddy)\
**Post date:** [May 20, 2022, 6:15am UTC](https://discourse.processing.org/t/copy-from-source-to-pgraphics/36958/2 "2022-05-20T06:15:35Z")

</div>

Your code runs on my machine. Of course, I don’t have the same video file.  
If the video is taking a moment to load, you might try moving the copying code into the “if available” block.

---

<div class="post-metadata">

**Author:** ![Luis\_Luethi1](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@Luis\_Luethi1](https://discourse.processing.org/u/Luis_Luethi1)\
**Post date:** [May 21, 2022, 8:39am UTC](https://discourse.processing.org/t/copy-from-source-to-pgraphics/36958/3 "2022-05-21T08:39:32Z")

</div>

hey thanks. It was odd, I simply rewrote the code in an another fashion and now it is working. I also do not know where the problem was.
