Processing, 類PImage中的get()用法介紹。
用法
pimg.get(x, y)pimg.get(x, y, w, h)pimg.get()
參數
pimg(PImage)任何 PImage 類型的對象x(int)像素的 x 坐標y(int)像素的 y 坐標w(int)要獲得的像素矩形的寬度h(int)要獲取的像素矩形的高度
返回
int or PImage
說明
讀取任何像素的顏色或抓取圖像的一部分。如果沒有指定參數,則返回整個圖像。使用x 和y 參數獲取一個像素的值。通過指定附加的width 和height 參數來獲取顯示窗口的一部分。獲取圖像時,x 和 y 參數定義圖像左上角的坐標,與當前的 imageMode() 無關。
如果請求的像素在圖像窗口之外,則返回黑色。返回的數字根據當前顏色範圍進行縮放,但此函數僅返回 RGB 值。例如,即使您可能使用 colorMode(HSB) 繪製了一個形狀,返回的數字也會是 RGB 格式。
使用 get(x, y) 獲取單個像素的顏色很容易,但不如直接從 pixels[] 獲取數據快。使用 pixels[] 的 get(x, y) 的等效語句是 pixels[y*width+x] 。有關詳細信息,請參閱pixels[] 的參考。
例子
PImage sky = loadImage("tokyo-sky.jpg");;
size(400, 400);
background(sky);
noStroke();
color c = sky.get(240, 360);
fill(c);
rect(100, 100, 200, 200);
PImage sky = loadImage("tokyo-sky.jpg");
size(400, 400);
background(sky);
PImage newSky = sky.get(200, 0, 200, 400);
image(newSky, 0, 0); 
相關用法
- Processing PImage.pixels[]用法及代碼示例
- Processing PImage.resize()用法及代碼示例
- Processing PImage.width用法及代碼示例
- Processing PImage.set()用法及代碼示例
- Processing PImage.save()用法及代碼示例
- Processing PImage.loadPixels()用法及代碼示例
- Processing PImage.filter()用法及代碼示例
- Processing PImage.updatePixels()用法及代碼示例
- Processing PImage.mask()用法及代碼示例
- Processing PImage.blend()用法及代碼示例
- Processing PImage.copy()用法及代碼示例
- Processing PImage.height用法及代碼示例
- Processing PImage用法及代碼示例
- Processing PI用法及代碼示例
- Processing Pulse用法及代碼示例
- Processing PShader用法及代碼示例
- Processing PVector.set()用法及代碼示例
- Processing PShape.enableStyle()用法及代碼示例
- Processing PVector.mag()用法及代碼示例
- Processing PWM.set()用法及代碼示例
- Processing PVector.normalize()用法及代碼示例
- Processing PVector.limit()用法及代碼示例
- Processing PShape用法及代碼示例
- Processing PFont.list()用法及代碼示例
- Processing PVector.div()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 PImage.get()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
