【问题标题】:Processing: transparent image over curves处理:曲线上的透明图像
【发布时间】:2013-03-07 11:46:03
【问题描述】:

我是处理新手。我想在曲线和椭圆上放一个 .jpg 或 .png ,这样他们只能看到图像透明的地方。 我的代码如下。它的问题是透明区域不是完全透明的,但是透明的白色和不透明的部分也降低了不透明度。

    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);
    }

更新:

我的代码中有这个:

    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();

图片不透明。 (但它会变成紫色,所以循环肯定会在每个像素上运行)

【问题讨论】:

  • "这样他们就只能看到图像透明的地方。"谁能看到什么?您是否希望仅在绘图中看到图像?也许是面具?请让自己更清楚。

标签: image png jpeg processing transparent


【解决方案1】:

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

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

【讨论】:

  • 但是如何读取像素的颜色?特别是,我如何读取 rgb 信息?
  • 这就是processing.org/reference 的用途,它列出了您需要的所有功能 =)
  • 现在我的代码中有这个,但这不起作用:loadPixels(); for(int i=0; i
猜你喜欢
  • 2018-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-01
  • 2011-12-21
  • 1970-01-01
相关资源
最近更新 更多