# Rotate Camera Image only, blend with Image from Animation

**URL:** <https://discourse.processing.org/t/rotate-camera-image-only-blend-with-image-from-animation/44747>\
**Category:** Coding Questions\
**Created:** [July 11, 2024, 11:12am UTC](https://discourse.processing.org/t/rotate-camera-image-only-blend-with-image-from-animation/44747 "2024-07-11T11:12:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![qualidat](https://avatars.discourse-cdn.com/v4/letter/q/a587f6/32.png) [@qualidat](https://discourse.processing.org/u/qualidat)\
**Post date:** [July 11, 2024, 11:12am UTC](https://discourse.processing.org/t/rotate-camera-image-only-blend-with-image-from-animation/44747/1 "2024-07-11T11:12:46Z")

</div>

Rotating an image is not normally a complicated matter. However, I have a somewhat complicated problem:

1. I get an image from a live camera
2. I read an image from an animation
3. I mix the images with blend and then show them on the screen

After a defect, the camera was replaced, but mounted upside down. I just wanted to rotate only the camera image using software before blending it … but how?

```auto
if(anima.available()){anima.read();}
if(camera.available()){camera.read();}
      
      camimg=camera.get(xd+xa,yd+ya,ww,hh);
      camimg.resize(dw,dh);
     
      aniimg=anima.get(0,0,anima.width,anima.height);
      aniimg.resize(dw,dh);

      aniimg.blend(camimg, 0, 0, dw, dh, 0, 0, dw, dh, MULTIPLY); 
      image(aniimg,0,0);

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2024, 11:20am UTC](https://discourse.processing.org/t/rotate-camera-image-only-blend-with-image-from-animation/44747/2 "2024-07-11T11:20:52Z")

</div>

> [@qualidat](#):
>
> After a defect, the camera was replaced, but mounted upside down. I just wanted to rotate only the camera image using software before blending it … but how?

One way:

> **[Images and Pixels](https://processing.org/tutorials/pixels/)**
>
> How to load and display images as well as access their pixels.

I have written code in the past to flip, mirror, rotate etc.

`:)`

---

<div class="post-metadata">

**Author:** ![qualidat](https://avatars.discourse-cdn.com/v4/letter/q/a587f6/32.png) [@qualidat](https://discourse.processing.org/u/qualidat)\
**Post date:** [July 11, 2024, 1:29pm UTC](https://discourse.processing.org/t/rotate-camera-image-only-blend-with-image-from-animation/44747/3 "2024-07-11T13:29:09Z")

</div>

thanks, have found, works … flip two axis is like rotate 180 degree

```auto
PImage flip_img(PImage imx)
{
  int wid = imx.width;
  int hig = imx.height;
  PImage ret = new PImage(wid,hig);
  
  for(int x=0; x<wid; x++)
  {
    for(int y=0; y<hig; y++)
    {
      ret.set(wid - 1 - x, hig - 1 - y , imx.get(x,y));
    }
  }
  return ret;
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2024, 3:37pm UTC](https://discourse.processing.org/t/rotate-camera-image-only-blend-with-image-from-animation/44747/4 "2024-07-11T15:37:34Z")

</div>

Another way:

```auto
String url = "http://learningprocessing.com/code/assets/sunflower.jpg";
PImage img;
PGraphics pg;

void setup()
  {
  size(400, 200);  
  img = loadImage(url);
  image(img, 0, 0);

  pg = createGraphics(img.width, img.height);
  pg.beginDraw();
  pg.translate(pg.width, 0);
  pg.scale(-1, 1);
  pg.image(img, 0, 0);
  pg.endDraw();
  
  image(img, 0, 0);
  image(pg, width/2, 0);
  noLoop();
  }

```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/f/7/f71cd4e9403b46bd57f899a7cd4c150fecf72583.jpeg)

`:)`
