-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reverse.cs
84 lines (62 loc) · 2.07 KB
/
Reverse.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Imaging;
using System.Drawing;
namespace Filtermap
{
class Reverse
{
public static Bitmap Reversetobmp(int[,] inimg) {
int R = 0, G = 0, B = 0;
Bitmap bi = new Bitmap(inimg.GetLength(0), inimg.GetLength(1));
for (int i = 0; i < bi.Height; i++)
{
for (int j = 0; j < bi.Width; j++)
{
Color pixel = bi.GetPixel(i, j);
try
{
if (inimg[j, i] < 0)
{
if (j + 1 < 256 && j - 1 >= 0 && i + 1 < 256 && i - 1 >= 0)
{
if (inimg[j + 1, i] > 0 && inimg[j - 1, i] > 0 && inimg[j, i + 1] > 0 && inimg[j, i - 1] > 0)
inimg[j, i] = 1;
else
inimg[j, i] = 0;
}
else
{
inimg[j, i] = 0;
}
}
}
catch (Exception e)
{
e.ToString();
}
R = inimg[j, i];
G = inimg[j, i];
B = inimg[j, i];
if (B > 0)
B = 255;
else if (B <= 0)
B = 0;
if (G > 0)
G = 255;
else if (G <= 0)
G = 0;
if (R > 0)
R = 255;
else if (R <= 0)
R = 0;
bi.SetPixel(j, i, Color.FromArgb(R, G, B));
}
}
return bi;
}
}
}