public void PixelsToArray() { List <byte> pixels = new List <byte>(); byte[] b = BitConverter.GetBytes(this.bfType); var pixel = b.Concat(BitConverter.GetBytes(bfSize)); b = BitConverter.GetBytes(bfReserved1); pixel = pixel.Concat(b); b = BitConverter.GetBytes(bfReserved2); pixel = pixel.Concat(b); b = BitConverter.GetBytes(bfOffBits); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biSize); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biWidth); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biHeight); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biPlanes); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biBitCount); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biCompression); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biSizeImage); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biXPelsPerMeter); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biYPelsPerMeter); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biClrUsed); pixel = pixel.Concat(b); b = BitConverter.GetBytes(biClrImportant); pixel = pixel.Concat(b); int n = this.picture.GetLength(1); int m = this.picture.GetLength(0); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { MyColor c = this.picture[j, i]; pixels.Add(c.Blue); pixels.Add(c.Green); pixels.Add(c.Red); } while (pixels.Count % 4 != 0) { pixels.Add(0); } } this.pixelData = pixels.ToArray(); pixel.ToArray().CopyTo(this.data, 0); }
public void Mirror() { MyColor[,] pixels = new MyColor[this.biWidth, this.biHeight]; for (int i = 0; i < this.biWidth; i++) { for (int j = 0; j < this.biHeight; j++) { pixels[i, j] = this.picture[this.biWidth - i - 1, j]; } } this.picture = pixels; }
public void Transpose() { MyColor[,] pixels = new MyColor[this.biHeight, this.biWidth]; for (int i = 0; i < this.biHeight; i++) { for (int j = 0; j < this.biWidth; j++) { pixels[i, j] = this.picture[this.biWidth - j - 1, this.biHeight - i - 1]; } } this.picture = pixels; int x = this.biWidth; this.biWidth = this.biHeight; this.biHeight = x; }
public void DataToArray() { this.picture = new MyColor[this.biWidth, this.biHeight]; int lineLen = this.pixelData.Length / this.biHeight; for (int i = 0; i < this.biHeight; i++) { int j = 0; int pos = 0; while (j < this.biWidth) { MyColor c = new MyColor(); c.Blue = this.pixelData[pos + lineLen * i]; pos++; c.Green = this.pixelData[pos + lineLen * i]; pos++; c.Red = this.pixelData[pos + lineLen * i]; pos++; this.picture[j, i] = c; j++; } } }