List<Point> list = new List<Point>();
private void button2_Click(object sender, EventArgs e)
{
List<byte[]> pointbytes = new List<byte[]>();
// OpenFileDialog dialog = new OpenFileDialog();
//dialog.Filter = "bmp文件(*.bmp)|*.bmp";
//if(dialog.ShowDialog() == DialogResult.OK)
//{
string file = "C:\\Users\\86166\\Desktop\\11.bmp";
string bmpname = System.IO.Path.GetFileNameWithoutExtension(file);
string writename = "File\\" + bmpname + ".psaf";
if (Directory.Exists("File\\" + bmpname + ".psaf"))
{
Directory.Delete("File\\" + bmpname + ".psaf");
}
Directory.CreateDirectory("File\\" + bmpname + "\\PSAF\\");
string save_file = "File\\" + bmpname + "\\";
Bitmap bmp = new Bitmap(file);
byte[] addarraybyte = new byte[8820];
for (int i = 0; i < list.Count; i++)
{
pointbytes.Add(convert(cut(bmp, (int)list[i].X, (int)list[i].Y)));
Array.Copy(pointbytes[i], 0, addarraybyte, 147 * i, pointbytes[i].Length);
}
}
private static byte[] cut(Bitmap image, int rex, int rey)
{
Rectangle region = new Rectangle(rex, rey, 7, 7);
byte[] bytes = new byte[7 * 7 * 3];
int index = 0;
for (int y = region.Y; y < region.Y + region.Height; y++)
{
for (int x = region.X; x < region.X + region.Width; x++)
{
// 获取当前像素的颜色
Color pixelColor = image.GetPixel(x, y);
//按BGR的顺序存放到数组中
bytes[index] = pixelColor.B; index += 1;
bytes[index] = pixelColor.G; index += 1;
bytes[index] = pixelColor.R; index += 1;
}
}
return bytes;
}
//将数组bytes转为s型输出数组byteArray
private static byte[] cut(Bitmap image, int rex, int rey)
{
Rectangle region = new Rectangle(rex, rey, 7, 7);
byte[] bytes = new byte[7 * 7 * 3];
int index = 0;
for (int y = region.Y; y < region.Y + region.Height; y++)
{
for (int x = region.X; x < region.X + region.Width; x++)
{
// 获取当前像素的颜色
Color pixelColor = image.GetPixel(x, y);
//按BGR的顺序存放到数组中
bytes[index] = pixelColor.B; index += 1;
bytes[index] = pixelColor.G; index += 1;
bytes[index] = pixelColor.R; index += 1;
}
}
return bytes;
}
private byte[] convert(byte[] byteArray)
{
List<List<List<byte>>> list = new List<List<List<byte>>>();
int index = 0;
// byte[,,] option = new byte[bmp.Height, bmp.Width, 3];
for (int i = 0; i < 7; i++)
{
list.Add(new List<List<byte>>());
for (int j = 0; j < 7; j++)
{
list[i].Add(new List<byte>());
for (int k = 0; k < 3; k++)
{
list[i][j].Add(byteArray[index++]);
}
list[i][j].Reverse();
}
}
for (int m = 0; m < 7; m++)
{
if (m % 2 != 0)
{
list[m].Reverse();
}
}
int ind = 0;
for (int i = 0; i < list.Count; i++)
{
for (int j = 0; j < list[i].Count; j++)
{
for (int k = 0; k < list[i][j].Count; k++)
{
byteArray[ind++] = list[i][j][k];
}
}
}
return byteArray;
}
private static byte[] cut(Bitmap image, int rex, int rey)
{
Rectangle region = new Rectangle(rex, rey, 7, 7);
byte[] bytes = new byte[7 * 7 * 3];
int index = 0;
for (int y = region.Y; y < region.Y + region.Height; y++)
{
for (int x = region.X; x < region.X + region.Width; x++)
{
// 获取当前像素的颜色
Color pixelColor = image.GetPixel(x, y);
//按BGR的顺序存放到数组中
bytes[index] = pixelColor.B; index += 1;
bytes[index] = pixelColor.G; index += 1;
bytes[index] = pixelColor.R; index += 1;
}
}
return bytes;
}
private byte[] convert(byte[] byteArray)
{
List<List<List<byte>>> list = new List<List<List<byte>>>();
int index = 0;
// byte[,,] option = new byte[bmp.Height, bmp.Width, 3];
for (int i = 0; i < 7; i++)
{
list.Add(new List<List<byte>>());
for (int j = 0; j < 7; j++)
{
list[i].Add(new List<byte>());
for (int k = 0; k < 3; k++)
{
list[i][j].Add(byteArray[index++]);
}
list[i][j].Reverse();
}
}
for (int m = 0; m < 7; m++)
{
if (m % 2 != 0)
{
list[m].Reverse();
}
}
int ind = 0;
for (int i = 0; i < list.Count; i++)
{
for (int j = 0; j < list[i].Count; j++)
{
for (int k = 0; k < list[i][j].Count; k++)
{
byteArray[ind++] = list[i][j][k];
}
}
}
return byteArray;
}
private byte[] convert(byte[] byteArray)
{
List<List<List<byte>>> list = new List<List<List<byte>>>();
int index = 0;
// byte[,,] option = new byte[bmp.Height, bmp.Width, 3];
for (int i = 0; i < 7; i++)
{
list.Add(new List<List<byte>>());
for (int j = 0; j < 7; j++)
{
list[i].Add(new List<byte>());
for (int k = 0; k < 3; k++)
{
list[i][j].Add(byteArray[index++]);
}
list[i][j].Reverse();
}
}
for (int m = 0; m < 7; m++)
{
if (m % 2 != 0)
{
list[m].Reverse();
}
}
int ind = 0;
for (int i = 0; i < list.Count; i++)
{
for (int j = 0; j < list[i].Count; j++)
{
for (int k = 0; k < list[i][j].Count; k++)
{
byteArray[ind++] = list[i][j][k];
}
}
}
return byteArray;
}