2013-03-18 57 views
0

Im新增至處理。我想將.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); 
    } 

UPDATE:

我有這個在我的代碼:

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

圖片不變得透明。 (但它變成紫色,所以循環肯定會在每個像素上運行)

+0

「,以便他們只能看到圖像透明的位置。」誰可以看到什麼?你只想在抽獎中看到圖像嗎?也許是面具?請讓自己更清楚。 – 2013-03-19 07:42:58

回答

1

tint()不會執行greenscreening。它會重新着色你的圖像(如果你使用非中性色),並設置混合透明度,所以通過色調(255,100),你的圖像不透明度約爲0.39。做綠屏(或在你的情況下,白屏),當你加載圖像時,你想穿過圖像的像素,然後設置不透明度爲0,無論何時r/g/b是255,有效地「移除」你所有的白色像素。

+0

但我該如何讀取像素的顏色?特別是,我如何閱讀rgb信息? – user1008673 2013-03-19 06:19:04

+0

這是http://processing.org/reference是什麼,它列出了你需要的所有功能=) – 2013-03-19 13:17:20

+0

我認爲我編輯了這條評論後,我發現這... – user1008673 2013-03-19 21:46:55