# Need help with function copy() and video

**URL:** <https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207>\
**Category:** Libraries\
**Created:** [December 13, 2020, 5:59pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207 "2020-12-13T17:59:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![toc\_toc\_toc](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@toc\_toc\_toc](https://discourse.processing.org/u/toc_toc_toc)\
**Post date:** [December 13, 2020, 5:59pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/1 "2020-12-13T17:59:03Z")

</div>

\<  
import processing.video.\*;

String PATH = “MVI\_3180.MP4”;  
Movie gare;

void setup() {

size(1440, 900);  
frameRate(30);  
gare = new Movie(this, PATH);  
gare.play();  
}

void movieEvent(Movie m) {  
m.read();  
}

void draw() {

image(gare, 0, 0, 1440, 900);

// SOURCE  
int sx = mouseX-75;  
int sy = mouseY-75;  
int sw = 150;  
int sh = 150;

// DESTINATION  
int dx = width/2-75;  
int dy = height/2-75;  
int dw = 150;  
int dh = 150;

copy (sx, sy, sw, sh, dx, dy, dw, dh);

//background(0);

noFill();  
fill(#ffffff);  
noStroke();  
ellipse(mouseX, mouseY, 10, 10);  
}

>

---

<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 14, 2020, 9:12pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/2 "2020-12-14T21:12:45Z")

</div>

Hello!

And welcome to the forum !

Great to have you here !

here is a version with an image instead of movie…

but it works

```auto
PImage gare; 

void setup() {

  size(1440, 900);
  frameRate(30);

  gare=loadImage("BB1bUFxv.jpg");

  //gare = new Movie(this, PATH);
  //gare.play();
}

//void movieEvent(Movie m) {
// m.read();
//}

void draw() {

  image(gare, 
    0, 0, 1440, 900);

  // SOURCE
  int sx = mouseX-75;
  int sy = mouseY-75;
  int sw = 150;
  int sh = 150;

  // DESTINATION
  int dx = width/2-75;
  int dy = height/2-75;
  int dw = 150;
  int dh = 150;

  copy (sx, sy, sw, sh, 
    dx, dy, dw, dh);

  //background(0);

  // noFill();
  fill(#ffffff);
  noStroke();
  ellipse(mouseX, mouseY, 10, 10);
}

```

---

<div class="post-metadata">

**Author:** ![toc\_toc\_toc](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@toc\_toc\_toc](https://discourse.processing.org/u/toc_toc_toc)\
**Post date:** [December 16, 2020, 1:26pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/3 "2020-12-16T13:26:46Z")

</div>

Hello,  
thank you so much your answer !  
and also for your greeting 😁

Unfortunately, I forgot to write that my problem was that I would like to have all the rest in black (juste the little square of pixel not in black --\> like if you was searching information in the video with your mouse)

Sorry for my English I’m from Switzerland haha 😉

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [December 16, 2020, 4:08pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/4 "2020-12-16T16:08:04Z")

</div>

Sure you’re actually wanting to use `copy()` and not `image()`?

eg.

```auto
background(0);
image(gare, dx, dy, dw, dh, sx, sy, sx + sw, sy + sh);

```

---

<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, 2020, 10:41pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/5 "2020-12-16T22:41:36Z")

</div>

> [@toc\_toc\_toc](#):
>
> I would like to have all the rest in black (juste the little square of pixel not in black

Okay, then you should not display the entire image at the start of draw()

here is the idea, I am not sure whether this works with movie images

```auto

PImage gare; 

void setup() {

  size(1440, 900);
  frameRate(30);

  gare=loadImage("BB1bUFxv.jpg");

  //gare = new Movie(this, PATH);
  //gare.play();
}

//void movieEvent(Movie m) {
// m.read();
//}

void draw() {

  background (0); // New. 

  //image(gare, 
  // 0, 0, 1440, 900); // No. 

  // SOURCE
  int sx = mouseX-75;
  int sy = mouseY-75;
  int sw = 150;
  int sh = 150;

  // DESTINATION
  int dx = width/2-75;
  int dy = height/2-75;
  int dw = 150;
  int dh = 150;

  PImage my = gare.get (sx, sy, sw, sh); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  image (my, 222, 222); 

  //background(0);

  // noFill();
  fill(#ffffff);
  noStroke();
  ellipse(mouseX, mouseY, 10, 10);
}

```

---

<div class="post-metadata">

**Author:** ![toc\_toc\_toc](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@toc\_toc\_toc](https://discourse.processing.org/u/toc_toc_toc)\
**Post date:** [December 17, 2020, 10:17am UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/6 "2020-12-17T10:17:57Z")

</div>

Yeaaaaah it’s work thank you so much !!  
I’m very grateful to you 😊  
but it just deform the size but it’s work !!

---

<div class="post-metadata">

**Author:** ![toc\_toc\_toc](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@toc\_toc\_toc](https://discourse.processing.org/u/toc_toc_toc)\
**Post date:** [December 17, 2020, 10:21am UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/7 "2020-12-17T10:21:15Z")

</div>

Oh yes it’s work also just small adjustments to be made but it works too thank you very much !!  
🙂

---

<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 17, 2020, 10:33am UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/8 "2020-12-17T10:33:14Z")

</div>

You could display the new small image also at mouse position.

Then you would see what’s directly underneath the mouse (real position of the section like in the movie)

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [December 17, 2020, 3:11pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/9 "2020-12-17T15:11:28Z")

</div>

The nine argument variant of `image(..)` will always be more efficient than `get()` (and potentially than `copy()`), with all the renderers, although particularly the non-default ones. So it’s worth looking at, even if not particularly well documented!

The key thing is that parameters 2-5 are the destination rectangle as position and dimensions. However 6-9 are the top-left and bottom-right coordinates of the source image. That’s why you have to add the source width to source x, and source height to source y. Upside of source being coordinates is that you can also have the second position to left and/or above the first to draw reversed.

If that sounds complicated, just play around with it! 😄

---

<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 17, 2020, 6:34pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/10 "2020-12-17T18:34:05Z")

</div>

ah, my apologies, I didn’t get what you did there…

---

<div class="post-metadata">

**Author:** ![toc\_toc\_toc](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@toc\_toc\_toc](https://discourse.processing.org/u/toc_toc_toc)\
**Post date:** [December 17, 2020, 8:08pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/11 "2020-12-17T20:08:31Z")

</div>

Yes it’s another possibility ! 😉  
thanks

---

<div class="post-metadata">

**Author:** ![toc\_toc\_toc](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@toc\_toc\_toc](https://discourse.processing.org/u/toc_toc_toc)\
**Post date:** [December 17, 2020, 8:09pm UTC](https://discourse.processing.org/t/need-help-with-function-copy-and-video/26207/12 "2020-12-17T20:09:07Z")

</div>

I will try and play with it !  
Thank you 😊 🙏
