-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read.cs
105 lines (94 loc) · 3.36 KB
/
Read.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Filtermap
{
class Read
{
Bitmap Obj;
int Width, Height;
public int[] INputStrt;
public int[,] GreyImage;
public int[,] Input;
public Bitmap Disp;
public Read(Bitmap Input)
{
Obj = Input;
Width = Obj.Width;
Height = Obj.Height;
ReadImage();
}
private void ReadImage()
{
int i, j;
GreyImage = new int[Width, Height]; //[Row,Column]
Input = new int[Width, Height]; //[Row,Column]
Bitmap image = Obj;
BitmapData bitmapData1 = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
unsafe
{
byte* imagePointer1 = (byte*)bitmapData1.Scan0;
for (i = 0; i < bitmapData1.Height; i++)
{
for (j = 0; j < bitmapData1.Width; j++)
{
GreyImage[j, i] = (int)((imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3.0);
Input[j, i] = (int)GreyImage[j, i];
//4 bytes per pixel
imagePointer1 += 4;
}//end for j
//4 bytes per pixel
imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 4);
}//end for i
}//end unsafe
image.UnlockBits(bitmapData1);
return;
}
public Bitmap Displayimage(int[,] image)
{
int i, j;
Bitmap output = new Bitmap(image.GetLength(0), image.GetLength(1));
BitmapData bitmapData1 = output.LockBits(new Rectangle(0, 0, image.GetLength(0), image.GetLength(1)),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
unsafe
{
byte* imagePointer1 = (byte*)bitmapData1.Scan0;
for (i = 0; i < bitmapData1.Height; i++)
{
for (j = 0; j < bitmapData1.Width; j++)
{
imagePointer1[0] = (byte)image[j, i];
imagePointer1[1] = (byte)image[j, i];
imagePointer1[2] = (byte)image[j, i];
imagePointer1[3] = 255;
//4 bytes per pixel
imagePointer1 += 4;
}//end for j
//4 bytes per pixel
imagePointer1 += (bitmapData1.Stride - (bitmapData1.Width * 4));
}//end for i
}//end unsafe
output.UnlockBits(bitmapData1);
return output;// col;
}
public int[] straight()
{
Disp = Displayimage(Input);
int k = 0;
INputStrt = new int[1849];
for (int i = 0; i < Width; i++)
{
for (int j = 0; j < Height; j++)
{
INputStrt[k++] = Input[i, j];
}
}
return INputStrt;
}
}
}