forked from processing-js/processing-js.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPImage_get_.html
More file actions
94 lines (88 loc) · 3.23 KB
/
Copy pathPImage_get_.html
File metadata and controls
94 lines (88 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
layout: default
---
<table cellpadding="0" cellspacing="0" border="0" class="ref-item">
<tr>
<th scope="row">Class</th>
<td>PImage</td>
</tr>
<tr class="name-row">
<th scope="row">Name</th>
<td><h3>get()</h3></td>
</tr>
<tr class="">
<th scope="row">Examples</th>
<td><div class="example"><img src="/reference/PImage_get.jpg" alt="example pic" /><pre class="margin">// @pjs preload must be used to preload the image
/* @pjs preload="tower.jpg"; */
PImage img = loadImage("tower.jpg");
background(img);
noStroke();
color c = img.get(60, 90);
fill(c);
rect(25, 25, 50, 50);</pre></div>
<div class="example"><img src="/reference/PImage_get2.jpg" alt="example pic" /><pre class="margin">// @pjs preload must be used to preload the image
/* @pjs preload="tower.jpg"; */
PImage img = loadImage("tower.jpg");
background(img);
PImage b = img.get(50, 0, 50, 100);
image(b, 0, 0);</pre></div></td>
</tr>
<tr class="">
<th scope="row">Description</th>
<td><p>Reads the color of any pixel or grabs a group of pixels. If no parameters are specified, the entire image is returned. Get the value of one pixel by
specifying an x,y coordinate. Get a section of the display window by specifing an additional <b>width</b> and <b>height</b> parameter.
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. Even though you may have drawn a shape with <b>colorMode(HSB)</b>, the numbers returned will be in RGB. </p>
<p>Getting the color of a single pixel with <b>get(x, y)</b> is easy, but not as fast as grabbing the data directly from <b>pixels[]</b>.
The equivalent statement to "get(x, y)" using <b>pixels[]</b> is "pixels[y*width+x]". Processing requires calling <b>loadPixels()</b> to load the display window data into
the <b>pixels[]</b> array before getting the values. </p>
<p>This function ignores <b>imageMode()</b>.</p></td>
</tr>
<tr class="">
<th scope="row">Syntax</th>
<td><pre><kbd>img</kbd>.get()</pre><br />
<pre><kbd>img</kbd>.get(<kbd>x</kbd>,<kbd>y</kbd>)</pre><br />
<pre><kbd>img</kbd>.get(<kbd>x</kbd>,<kbd>y</kbd>,<kbd>width</kbd>,<kbd>height</kbd>)</pre><br /></td>
</tr>
<tr class="">
<th scope="row">Parameters</th>
<td>
<table cellpadding="0" cellspacing="0" border="0">
<tr class="">
<th scope="row">img</th>
<td>PImage: any variable of type PImage</td>
</tr>
<tr class="">
<th scope="row">x</th>
<td>int: x-coordinate of the pixel</td>
</tr>
<tr class="">
<th scope="row">y</th>
<td>int: y-coordinate of the pixel</td>
</tr>
<tr class="">
<th scope="row">width</th>
<td>int: width of pixel rectangle to get</td>
</tr>
<tr class="">
<th scope="row">height</th>
<td>int: height of pixel rectangle to get</td>
</tr>
</table>
</td>
</tr>
<tr class="">
<th scope="row">Returns</th>
<td>color or PImage</td>
</tr>
<tr class="">
<th scope="row">Usage</th>
<td>Web & Application</td>
</tr>
<tr class="">
<th scope="row">Related</th>
<td><a href="../reference/set_">set()</a><br />
<a href="../reference/pixels">pixels[]</a><br />
<a href="../reference/copy_">copy()</a></td>
</tr>
</table>