Blending two PGraphics - how would this work? - what is the syntax?

The Processing reference for blend suggests there is flexibility of specifying the destination image as well as the source image.

> Blends a region of pixels from one image into another (or in itself again) with full alpha channel support. There is a choice of the following modes to blend the source pixels (A) with the ones of pixels in the destination image (B)

But in the syntax you only get to specify the source image. The destination image seems hardwired to be the image in the sketch window.

But what if I want the destination image to be another PGraphics? Can I do this? What would be the syntax?

thanks!

You can call blend() on a PGraphics object.

1 Like

Aha, good. What is the syntax? As I said, the Processing documentation for Blend just tells you how to specify source, not the destination. And in the examples it’s aways the Pimage that’s being operated on. How would you get it to operate on a PGraphics that you specify?

img1.blend(img2,…);

1 Like


PImage c1, c2; 

void setup() {
  size(500, 500);

  c1 = loadImage("c1.jpg");
  c2 = loadImage("c2.jpg");
}

void draw() {

  image(c1, 0, 0);

  c1.blend(c2, 
    mouseX, mouseY, 100, 100, 
    mouseX, mouseY, 100, 100, 
    DARKEST); // LIGHTEST

  image(c1, 0, 0);
}

1 Like

Great your example is the answer to the question I meant to ask!

1 Like

Hello,

References are here for PImage blend():
https://processing.org/reference/PImage.html < blend method is listed
https://processing.org/reference/PImage_blend_.html

Reference to blend():
https://processing.org/reference/blend_.html

:)

2 Likes