Accessing values in Color32 or convert to Byte array

I am trying to access pixel R, G and B values in a rather large web camera feed, and was led towards the path of using the .GetPixels32, since this was supposed to be the fastest option, and indeed it seems so. Now I just need to access the individual values, in order to measure them against certain limits, E.G. is this red enough to be the previously introduced red object? But I can’t seem to figure out how to access the individual values (a,b,g,r), (or as it says in the debug: RGBA).

What I know about the GetPixels32:

What I know about the Color32:

Currently I am trying to feed the RGB values into an array, which is 16 columns wide, 16 rows high, and has 3 values (the colors):

using UnityEngine;
using System.Collections;

public class CamTexture : MonoBehaviour {
	public byte[,,] colorArr = new byte[16,16,3];
	public static WebCamTexture webcam;
	private Color32[] ImgMatrix;
	void Start (){
		webcam = new WebCamTexture();
		renderer.material.mainTexture = webcam;
		ImgMatrix = new Color32[webcam.width * webcam.height];

		//This is a desperate and vague attempt at feeding any value into colorArr...
		colorArr[0,0,0] = ImgMatrix[0];

Any, also different ways of approaching the problem, ways of doing this would be amazing. The values are there; the Debug.Log shows the values just fine when I feed it the ImgMatrix[0], i just don’t see how to get at them…

I don’t quite understand what you’re trying to do with that byte array.

If you’re only trying to access the color values of pixels at position x,y then the solution is quite simple. Your ImgMatrix is an array of Color structs so it has all the information you need.
To get the Color struct at position x,y:

Color32 col = ImgMatrix[y*webcam.width + x];

Why does this work? Let’s say our camera has 3 lines and looks like this:


Each character is one pixel on our cam. This two dimensonal image is actually stored as one continuous array which looks like this:


And that’s your ImgMatrix array.

Right, in my way too common “Why didn’t I think of that before!?” manner, I realized what needed to be done: ImgMatrix[0].r, or col[0].r, returns the red value of the color32 struct. And so on and so forth with g, b and a. Hope this helps someone who’s also stuck at this point get over it faster than I did.