Reputation: 4741
Sorry for dummy question but I am new in this and I could not find the answers.
Stride calculates as bitFrame.PixelWidth * ((bitFrame.Format.BitsPerPixel + 7) / 8);
Then I using bitFrame.CopyPixels(pixels, stride, 0); //(byte[] pixels)
And I have the function of processing current pixel (that is a struct.)
struct pixel {
float r;
float g;
float b;
};
And there is also pixel processing function pixel processPixel(int x, int y)
. How could I use this function with my buffer ? I think it must be called somehow like this:
for(int i = 0; i < height; i++) {
for(int j = 0; j < height; j++) {
processPixel(i, j);
// But how could I use this function with my byte[] buffer?
// And what exactly in this buffer?
// (why stride*height = 4*width*height? cause there are 3 values for pixel RGB)
}
}
Upvotes: 1
Views: 1186
Reputation: 25601
Stride is the number of bytes per row of pixels regardless of how many of those pixels are part of the image, so you have to use stride in calculating which bytes to affect based on 2-D coordinates:
void processPixel(int x, int y)
{
// This is if your image format is 4 bytes per pixel such as RGBA
int startByteIndex = x * 4 + y * stride;
}
Edit: I was too rushed -- answer updated based on comments.
Upvotes: 0