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_pixels.html
More file actions
69 lines (64 loc) · 2.33 KB
/
Copy pathPImage_pixels.html
File metadata and controls
69 lines (64 loc) · 2.33 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
---
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>pixels[]</h3></td>
</tr>
<tr class="">
<th scope="row">Examples</th>
<td><div class="example"><img src="/reference/PImage_pixels.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");
int dimension = (img.width*img.height);
img.loadPixels();
for (int i=0; i < dimension; i+=2) {
img.pixels[i] = color(0, 0, 0);
}
img.updatePixels();
image(img, 0, 0);</pre></div></td>
</tr>
<tr class="">
<th scope="row">Description</th>
<td>Array containing the values for all the pixels in the image. These values are of the color datatype.
This array is the size of the image, meaning if the image is 100x100 pixels, there will be 10000 values and if the window is 200x300 pixels, there will be 60000 values.
The <b>index</b> value defines the position of a value within the array. For example, the statement <b>color b = img.pixels[230]</b> will set the variable b equal to the value at that
location in the array. Before accessing this array, the data must loaded with the <b>loadPixels()</b> method. After the array data has been modified,
the <b>updatePixels()</b> method must be run to update the changes. Without <b>loadPixels()</b>, running the code may (or will in future releases) result in a NullPointerException.</td>
</tr>
<tr class="">
<th scope="row">Syntax</th>
<td><pre><kbd>img</kbd>.pixels[<kbd>index</kbd>]</pre></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">index</th>
<td>int: must not exceed the size of the array</td>
</tr>
</table>
</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/get_">get()</a><br />
<a href="../reference/set_">set()</a><br />
<a href="../reference/blend_">blend()</a><br />
<a href="../reference/copy_">copy()</a><br /></td>
</tr>
</table>