2011-11-13 33 views
2

我想製作一個小小的photoshop javascript。從技術上講,我只需要知道如何像素的顏色值AF如果他們在每三個整數值數組比較,例如:(僞)比較Photoshop中的像素值

for all pixels x 
    for all pixels y 
     if left pixel's green channel is bigger than red channel: 
      set the blue channel to 25 
     else 
      if the blue channel is greater than 50 
       set the green channel to 0 
文檔中

,有一噸的東西像過濾器,文本和圖層你可以做,但你怎麼做這樣簡單的事情?

回答

1

閱讀,然後在Photoshop腳本寫作像素值的確不是,因爲它可以作爲簡單的......看看下面的腳本反轉圖像的藍色通道:

var doc = app.open(new File("~/Desktop/test1.bmp")); 

var sampler = doc.colorSamplers.add([0, 0]); 

for (var x = 0; x < doc.width; ++x) { 
    for (var y = 0; y < doc.height; ++y) {   

     sampler.move([x, y]); 
     var color = sampler.color; 

     var region = [ 
      [x, y], 
      [x + 1, y], 
      [x + 1, y + 1], 
      [x, y + 1], 
      [x, y] 
     ]; 

     var newColor = new SolidColor(); 
     newColor.rgb.red = color.rgb.red; 
     newColor.rgb.green = 255 - color.rgb.green; 
     newColor.rgb.blue = color.rgb.blue; 

     doc.selection.select(region); 
     doc.selection.fill(newColor); 

    } 
} 

我不知道如果有更漂亮的設置像素顏色的方式比選擇+填充技巧。

這個腳本運行速度超慢,所以也許Photoshop腳本不是像素處理的最佳工具...

+0

謝謝。關於性能:我認爲我可以用photoshop操縱像素是多麼愚蠢:D –