0

Im new to Processing. I would like to put a .jpg or .png over curves and ellipses, so that they can see only where the image is transparent. My code is below. The problem with it is that the transparent area is not fully transparent, but transparent white and the not-transparent parts have also decreased opacity.

    PImage img;

    void setup() {
      size(300,500);
      frameRate(30); 
      strokeWeight(4);   
      img = loadImage("sziluettmeret.jpg"); 
    }

   void draw() {
        background(0, 50, 70);  
        stroke(0,70,90);
        noFill();
        beginShape();
        curveVertex(-100,  -100);
        curveVertex(10, 10);
        curveVertex(250,  250);
        curveVertex(300,  300);
        endShape();

       fill(255);
       ellipse(20 ,20,15,15);

       noFill();
       tint(255, 100);
       image(img, 0, 0);
    }

UPDATE:

I have this in my code:

    loadPixels();
    for(int i=0; i < img.pixels.length; i++) {
    tmpColor = img.pixels[i];
    tmpRed = red(tmpColor);
    tmpGreen = blue(tmpColor);
    tmpBlue = green(tmpColor);
    tmpAlpha = 255 - ((tmpRed + tmpGreen + tmpBlue)/3);
    img.pixels[i] = color(2*tmpRed,tmpGreen/2,tmpBlue,0); 
    if(0xFFFFFF == tmpColor)


      }
     updatePixels();

The picture does not become transparent. (But it becomes purple, so the loop runs on every pixel for sure)

4

1 回答 1

1

tint() 不做绿屏。它将重新着色您的图像(如果您使用非中性颜色),并设置混合透明度,因此使用 tint(255,100),您有效地为图像提供了(大约)0.39 的不透明度

如果你想做绿屏(或者在你的情况下,白屏),你想在加载图像时遍历图像的像素,然后在 r/g/b 为 255 时将不透明度设置为 0,有效地“去除”你所有的白色像素。

于 2013-03-18T23:44:32.333 回答