static class BitmapExtensions
{
static IEnumerable <Point> GenerateIndexes (this Bitmap inst)
{
for (int y = 0; y < inst.Height; y++)
for (int x = 0; x < inst.Width; x++)
yield return new Point (x, y);
}
public static Color [] DumpPixels (this Bitmap inst)
{
IEnumerable <Point> points = inst.GenerateIndexes ();
return points.Select (point => inst.GetPixel (point.X, point.Y)).ToArray ();
}
public static void LoadPixels (this Bitmap inst, Color [] dump)
{
foreach (Point point in inst.GenerateIndexes ())
inst.SetPixel (point.X, point.Y, dump [point.X + point.Y]);
}
}
static class Program
{
public static void Main ()
{
Bitmap bmp = new Bitmap (@"/home/red-agent/Downloads/shit.JPG");
Color [] dump = bmp.DumpPixels ();
bmp.LoadPixels (dump);
Console.WriteLine (bmp.Size);
}
}