static class BitmapExtensions static IEnumerable Point GenerateIndexes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
}
}