首页 > 文档 > get()读取像素颜色
2017
08-09

get()读取像素颜色

Name

get()读取像素颜色

   

Examples

get()读取像素颜色 - 第1张  | Processing编程艺术get()读取像素颜色 - 第2张  | Processing编程艺术get()读取像素颜色 - 第3张  | Processing编程艺术

PImage myImage = loadImage(“apples.jpg”);

image(myImage, 0, 0);

PImage c = get();

image(c, width/2, 0);

get()读取像素颜色 - 第4张  | Processing编程艺术get()读取像素颜色 - 第5张  | Processing编程艺术get()读取像素颜色 - 第6张  | Processing编程艺术

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 格式进行。

 

获取单个像素的颜色 (xy) 很容易, 但不能像从像素 [] 直接抓取数据那样快。使用像素 [] 获取 (xy) 的等效语句是像素 [y * + x]。有关详细信息, 请参阅像素 [] 的参考。

Syntax

get(x, y)

get(x, y, w, h)

get()

Parameters

x

int: x-coordinate of the pixel

像素的 x 坐标

y

int: y-coordinate of the pixel

像素的 y 坐标

w

int: width of pixel rectangle to get

要获取的像素矩形的宽度

h

int: height of pixel rectangle to get

要获取的像素矩形的高度

Returns

int or PImage

Related

set()
pixels[]
copy()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。