-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImage.cs
140 lines (113 loc) · 3.76 KB
/
Image.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
namespace Resourses.Visual;
public class Image
{
//[i]-Parameters
private Pixel[,] pixels;
//[i]-Constructors
public Image(int height, int width)
{
pixels = new Pixel[height, width];
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
pixels[y, x] = new Pixel();
}
}
}
public Image(int size) : this(size, size)
{
//[i]-Creates an scuare image
}
//[i]-Acces to parameters
public void SetPixel(int i, int j, Pixel thePixel)
{
this.pixels[i,j] = thePixel;
}
public Pixel GetPixel(int i, int j){
return pixels[i,j];
}
public int GetLength(int Dimention)
{
return (Dimention != 0 && Dimention !=1) ? -1 : pixels.GetLength(Dimention);
}
//[i]-Operations
public void Print()
{
for(int i = 0; i < pixels.GetLength(0); i++)
{
Console.WriteLine("");
for (int j = 0; j < pixels.GetLength(1); j++)
{
pixels[i,j].Print();
}
}
}
public void Copy(Image a)
{
this.pixels = new Pixel[a.GetLength(0), a.GetLength(1)];
for (int i = 0; i<a.GetLength(0); i++)
{
for(int j = 0; j<a.GetLength(1); j++)
{
this.pixels[i,j] = a.GetPixel(i, j);
}
}
}
public static Image CreateCopy(Image a)
{
Image b = new (a.GetLength(0), a.GetLength(1));
/*
Unhandled exception. System.OverflowException: Arithmetic operation resulted in an overflow.
at Resourses.Visual.Image..ctor(Int32 width, Int32 height) in F:\+++Programación+++\Pro001\Resourses\Visual\Image.cs:line 12
at Resourses.Visual.Image.CreateCopy(Image a) in F:\+++Programación+++\Pro001\Resourses\Visual\Image.cs:line 65
at Resourses.Visual.Image.AddLayer(Image a, Image b, Int32 col, Int32 row) in F:\+++Programación+++\Pro001\Resourses\Visual\Image.cs:line 82
at Resourses.Visual.Camera.CameraTest(Maze maze) in F:\+++Programación+++\Pro001\Resourses\Visual\Camera.cs:line 51
at PRO001.MiniTest.PreMadeMaze() in F:\+++Programación+++\Pro001\MiniTest.cs:line 53
at PRO001.MiniTest.Run() in F:\+++Programación+++\Pro001\MiniTest.cs:line 36
at Program.Main(String[] args) in F:\+++Programación+++\Pro001\Program.cs:line 12
*/
for (int i = 0; i<a.GetLength(0); i++)
{
for(int j = 0; j<a.GetLength(1); j++)
{
b.SetPixel(i,j, a.GetPixel(i, j));
}
}
return b;
}
//[i]-Operations with Images
public static Image AddLayer(Image a, Image b, int row, int col)
{
Image c = Image.CreateCopy(a);
/*if (a.GetLength(0) < b.GetLength(0) || a.GetLength(1) < b.GetLength(1))
{
return a;
}*/
for (int i = 0; i<b.GetLength(0); i++)
{
for(int j = 0; j<b.GetLength(1); j++)
{
if(b.GetPixel(i,j) != null && a.InRange(i+row, j+col))
{
c.SetPixel(i+row, j+col, b.GetPixel(i,j));
}
}
}
return c;
}
public static Image AddLayer(Image a, Image b)
{
return AddLayer(a, b, 0, 0);
}
private bool InRange(int i, int j)
{
return i < pixels.GetLength(0) &&
j < pixels.GetLength(1) &&
i >= 0 && j >= 0;
}
/*
here I should add some methods for operations between images like adding them in some way
*/
}