Error with getting pixels
I have tried to create some code to get the pixels of an uploaded image but the function doesn't seem to work correctly. It gives extremely strange outputs so it isn't that the r,g,b values are looking at the wrong index in the array. It does work for black and white but no colours. Does anyone know why?
This is the part of my code where the error occurs
var pixelData = createBytes(width, height);
string oldr = "0", oldb = "0", oldg = "0";
string[] compressed = new string[height * width];
int godown = 0;
var path = op.FileName;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = y * (width*4) + 4 * x;
byte blue = pixelData[index];
byte green = pixelData[index + 1];
byte red = pixelData[index + 2];
int arraySlot = x +(y*width);int StandardArraySlot = arraySlot - godown;
string r = red.ToString("D3"); string g = green.ToString("D3"); string b = blue.ToString("D3");
MessageBox.Show(r+" "+g+" "+b);
public byte[] createBytes(int width,int height)
{
int stride = width * 4;
byte[] pixelData = new byte[height * stride];
image.CopyPixels(new Int32Rect(0, 0, width, height), pixelData, stride, 0);
return pixelData;
}
This is the part of my code where the error occurs
var pixelData = createBytes(width, height);
string oldr = "0", oldb = "0", oldg = "0";
string[] compressed = new string[height * width];
int godown = 0;
var path = op.FileName;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = y * (width*4) + 4 * x;
byte blue = pixelData[index];
byte green = pixelData[index + 1];
byte red = pixelData[index + 2];
int arraySlot = x +(y*width);int StandardArraySlot = arraySlot - godown;
string r = red.ToString("D3"); string g = green.ToString("D3"); string b = blue.ToString("D3");
MessageBox.Show(r+" "+g+" "+b);
public byte[] createBytes(int width,int height)
{
int stride = width * 4;
byte[] pixelData = new byte[height * stride];
image.CopyPixels(new Int32Rect(0, 0, width, height), pixelData, stride, 0);
return pixelData;
}
