Can someone explain me how it's calculated row and column?
byte[] pixel = new byte[img.Stride * img.Height];
for (l=0; l< pixel.Length -4;l+=4 )
{
row= l/img.Stride;
column=(l% img.Stride)/4;
....
}
Can someone explain me how it's calculated row and column?
byte[] pixel = new byte[img.Stride * img.Height];
for (l=0; l< pixel.Length -4;l+=4 )
{
row= l/img.Stride;
column=(l% img.Stride)/4;
....
}
You can refer the link, c# scan0 and stride
The stride is the width of a single row of pixels (a scan line), rounded up to a four-byte boundary. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
If you want to move from one row to the next, you need to add the stride to the address of the row you're currently looking at. Rows are aligned to 4 byte boundaries so that all kinds of code can access it more efficiently. (Various operations in CPUs are optimized to work on 4 byte or 8 byte boundaries.)
Thanks, Christo