# Convert color notation in an array

**URL:** <https://discourse.processing.org/t/convert-color-notation-in-an-array/15972>\
**Category:** Coding Questions\
**Created:** [November 30, 2019, 8:17am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972 "2019-11-30T08:17:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stupidquestion](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@stupidquestion](https://discourse.processing.org/u/stupidquestion)\
**Post date:** [November 30, 2019, 8:17am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972/1 "2019-11-30T08:17:47Z")

</div>

so, i want to take an inventory of a bunch of my pixels in an array, and loadPixels() seems to generate that array fine, but I can’t figure out how to read that data, much less use it with other code.

any idea how to convert it all into rgb values I (and other bits of code) can use? preferably en masse?

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [November 30, 2019, 9:43am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972/2 "2019-11-30T09:43:02Z")

</div>

Color information is stored in what’s referred to as a packed 32-bit integer, representing alpha, red, green and blue. Processing provides convenience methods that allow you to extract both hsb and rgb color information:-

```java
get(x, y); // returns a color value from pixel array at a coordinate
color c = get(x, y);
alpha(c);
red(c);
blue(c);
green(c)
hue(c);
saturation(c);
brightness(c);

```

Although if you want to do this efficiently you may need learn about bitwise operations.  
You can use `get` to get the color at a particular `x`, `y` coordinates in the pixel array, the reference is your friend.

---

<div class="post-metadata">

**Author:** ![stupidquestion](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@stupidquestion](https://discourse.processing.org/u/stupidquestion)\
**Post date:** [December 1, 2019, 5:51am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972/3 "2019-12-01T05:51:35Z")

</div>

so I need to make a second array copying data from the first with get (x y) for each pixel rather than operating on the data in the loadPixels array. okay!

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 1, 2019, 7:16am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972/4 "2019-12-01T07:16:54Z")

</div>

sorry, that sounds even more confused?  
possibly try again,

there are 2 ways to get to the color of a pixel or set it.  
SLOW and EASY

```auto
color c = get(x, y);
set(x,y,c);

```

FAST and TRICKY

```auto
loadPixels();
int i = x + y * width;
color c = pixels[i];
pixels[i] = c;
updatePixels();

```

even check [pixelDensity() / Reference / Processing.org](https://processing.org/reference/pixelDensity_.html)

* * *

once you got the color here named ‘c’  
you can read/change it

> [@monkstone](#):
>
> alpha(c); red(c); blue(c); green(c) hue(c); saturation(c); brightness(c);

read works anyway, for understand / write must know the

> **[colorMode() / Reference](https://processing.org/reference/colorMode_.html)**
>
> Changes the way Processing interprets color data. By default, the parameters for fill(), stroke(), background(), and color() are defined by values between 0 and 255 using t…

also can use more faster bit operations on it.

* * *

so partial copy to array / smaller array or image is possible this way,  
but depending on what you need

> **[PImage / Reference](https://processing.org/reference/PImage.html)**
>
> Datatype for storing images. Processing can display .gif, .jpg, .tga, and .png images. Images may be displayed in 2D and 3D space. Before an image is used, it must be loade…

[copy() / Reference / Processing.org](https://processing.org/reference/PImage_copy_.html) the 9 parameter usage  
might already do the job.

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [December 1, 2019, 7:51am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972/5 "2019-12-01T07:51:56Z")

</div>

If you told us what you wanted to do with the colors we could help you more, it is quite possible you don’t need to do individual pixel manipulation at all, when you can do things like apply a [filter](https://processing.org/reference/filter_.html) to graphics object or [blend](https://processing.org/reference/blend_.html). For crazy weird stuff someone might have already created a [glsl filter](https://github.com/SableRaf/Filters4Processing) you could use that’s probably a bit advanced.

---

<div class="post-metadata">

**Author:** ![stupidquestion](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@stupidquestion](https://discourse.processing.org/u/stupidquestion)\
**Post date:** [December 2, 2019, 4:29am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972/6 "2019-12-02T04:29:01Z")

</div>

reading the color data, modifying sounds with it. the sounds bit was pretty intuitive and the documentation got me where I was going up until the part where i might base something on the total amount of red in the left side of the image minus the amount of blue in the top right corner

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [December 2, 2019, 9:28am UTC](https://discourse.processing.org/t/convert-color-notation-in-an-array/15972/7 "2019-12-02T09:28:36Z")

</div>

There is an example sketch that should help you get started:-  
[Histogram Sketch](https://processing.org/examples/histogram.html)
