Name |
get()读取像素颜色 |
||||||||
Examples |
PImage myImage = loadImage(“apples.jpg”); image(myImage, 0, 0); PImage c = get(); image(c, width/2, 0);
PImage myImage = loadImage(“apples.jpg”); image(myImage, 0, 0); color c = get(25, 25); fill(c); noStroke(); rect(25, 25, 50, 50); |
||||||||
Description |
Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. Use the x and y parameters to get the value of one pixel. Get a section of the display window by specifying additional w and h parameters. When getting an image, the x and yparameters define the coordinates for the upper-left corner of the image, regardless of the current imageMode(). If the pixel requested is outside of the image window, black is returned. The numbers returned are scaled according to the current color ranges, but only RGB values are returned by this function. For example, even though you may have drawn a shape with colorMode(HSB), the numbers returned will be in RGB format. Getting the color of a single pixel with get(x, y) is easy, but not as fast as grabbing the data directly from pixels[]. The equivalent statement to get(x, y) using pixels[] is pixels[y*width+x]. See the reference for pixels[] for more information. 读取任何像素的颜色或抓取图像的某个部分。如果未指定参数, 则返回整个图像。使用 x 和 y 参数获取一个像素的值。通过指定额外的 w 和 h 参数来获取显示窗口的一部分。获取图像时, x 和 y 参数定义图像左上角的坐标, 而不考虑当前的 imageMode ()。
如果所请求的像素位于图像窗口之外, 则返回黑色。返回的数字根据当前的颜色范围进行缩放, 但此函数只返回 RGB 值。例如, 即使您可能已绘制了带有 colorMode (HSB) 的形状, 但返回的数字将以 RGB 格式进行。
获取单个像素的颜色 (x、y) 很容易, 但不能像从像素 [] 直接抓取数据那样快。使用像素 [] 获取 (x、y) 的等效语句是像素 [y * 宽 + x]。有关详细信息, 请参阅像素 [] 的参考。 |
||||||||
Syntax |
get(x, y) get(x, y, w, h) get() |
||||||||
Parameters |
|
||||||||
Returns |
int or PImage |
||||||||
Related |
set() |
- 本文固定链接: http://iprocessing.cn/2017/08/09/get读取像素颜色/
- 转载请注明: 卡萨布兰卡 于 Processing编程艺术 发表