How to calculate padding when using direct access to image pixels? The code below should change all pixels to white, but System.AccessViolationException appears.
struct Pixel { public byte Blue; public byte Green; public byte Red; } public void startHandle() { Bitmap pic = new Bitmap(Path); var picBits = pic.LockBits(new Rectangle(0, 0, pic.Width, pic.Height), ImageLockMode.ReadWrite, pic.PixelFormat); unsafe { //получение указателя на первый пиксель изображения Pixel* px = (Pixel*)((byte*)picBits.Scan0); int padding = picBits.Stride - (pic.Width * sizeof(Pixel)); for (int j = 0; j < pic.Height - 1; j++) { for (int k = 0; k < pic.Width - 1; k++) { px->Blue = 255; px->Green = 255; px->Red = 255; px += sizeof(Pixel); } px += padding; } } pic.UnlockBits(picBits); }