public void Box(int X, int Y, int Width, int Height, uint Value) { if ((X + Width <= 0) || (X >= m_Width) || (Y + Height <= 0) || (Y >= m_Height)) { return; } if (X < 0) { Width += X; X = 0; } if (X + Width >= m_Width) { Width = m_Width - X; } if (Y < 0) { Height += Y; Y = 0; } if (Y + Height >= m_Height) { Height = m_Height - Y; } switch (BitsPerPixel) { case 8: for (int i = 0; i < Height; ++i) { for (int j = 0; j < Width; ++j) { m_ImageData.SetU8At(j + X + BytesPerLine * (Y + i), (byte)Value); } } break; case 24: for (int i = 0; i < Height; ++i) { for (int j = 0; j < Width; ++j) { m_ImageData.SetU8At((j + X) * 3 + BytesPerLine * (Y + i), (byte)(Value & 0xff)); m_ImageData.SetU8At((j + X) * 3 + BytesPerLine * (Y + i) + 1, (byte)((Value & 0xff00) >> 8)); m_ImageData.SetU8At((j + X) * 3 + BytesPerLine * (Y + i) + 2, (byte)((Value & 0xff0000) >> 16)); } } break; case 32: for (int i = 0; i < Height; ++i) { for (int j = 0; j < Width; ++j) { m_ImageData.SetU32At((j + X) * 4 + BytesPerLine * (Y + i), Value); } } break; default: throw new NotSupportedException("Bitdepth " + BitsPerPixel + " not supported yet"); } }