You have approached the task from the wrong side. You, apparently, are trying to make a 24-bit data type to arrange it in an array that will repeat the image in structure. But in C #, this is difficult to do.
Instead, you can make a separate class with an indexer that will look like an array from the outside - and inside it will itself correctly distribute the pixel colors by bytes:
public class BitmapAccessor { private byte[] scan0; // Или любое другое хранилище private int stride; // (3 * width + 3) / 4 * 4. Ну или можно взять это число из BitmapData.Stride // ... public Color this[int x, int y] { get { var index = 3 * x + stride * y; return Color.FromArgb(scan0[index], scan0[index+1], scan0[index+2]); // точный формат не помню, возможно аргументы надо поменять местами } set { var index = 3 * x + stride * y; scan0[index] = value.R; scan0[index+1] = value.G; scan0[index+2] = value.B; } } }
byte. But why? I would simply use an array of bytes corresponding to the memory fill, and write procedures that read / write the value at the index. (By the way, do not forget about stride.) - VladDInt24, are you going to copy it into memory of the image byte-by-byte? (Because, due to the alignment, you most likely will not be able to blit it). Believe my experience will be slow. (However, try it.) - VladDuintmatrix viaBuffer.BlockCopyto work with it in 2D coordinates. But theoretically, I wonder how it, for example, can be decomposed into a matrix of 24 bits fromBitmapData.Scan0. - Artyom Ionash