Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
- {
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void Form1_Load_1(object sender, EventArgs e)
- {
- }
- public void button1_Click(object sender, EventArgs e)
- {
- string path = textBox1.Text;
- converter.convert(path);
- }
- public void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- }
- public class converter
- {
- public static void convert(string path)
- {
- //Вывод в ту же директорию, но .csv
- string csv_path = path;
- csv_path = csv_path.Replace("bmp", "csv");
- Color[][] colorMatrix = GetBitMapColorMatrix(path, csv_path);
- MessageBox.Show("Вывод успешно завершен в файлы " + csv_path + " и " + csv_path.Replace(".csv","_info.txt"));
- }
- //Функция получения ARGB каждого пикселя
- public static Color[][] GetBitMapColorMatrix(string bitmapFilePath, string csv_path)
- {
- //writer
- Encoding enc = Encoding.GetEncoding(1251);
- FileStream output = new FileStream(csv_path, FileMode.Create);
- StreamWriter writer = new StreamWriter(output, enc);
- //Сам метод
- Color[][] colorMatrix; //объявляем
- using (var b1 = new Bitmap(bitmapFilePath))
- {
- b1.RotateFlip(RotateFlipType.Rotate270FlipY);
- int hight = b1.Height;
- int width = b1.Width;
- colorMatrix = new Color[hight][]; //инициализируем
- for (int i = 0; i < hight; i++)
- {
- colorMatrix[i] = new Color[width];
- for (int j = 0; j < width; j++)
- {
- colorMatrix[i][j] = b1.GetPixel(i, j);
- writer.Write(colorMatrix[i][j] + ";"); //Тут же печатаем
- }
- writer.Write("\n");
- }
- writer.Close();
- string info_path = csv_path.Replace(".csv","_info.txt");
- string[] pixelFormat = b1.PixelFormat.ToString().Replace("Format", "").Replace("bpp", ";").Split(';');
- string[] info_contain = new string[3];info_contain[0] = "размер изоображения:" + b1.Height + "x" + b1.Width; info_contain[1] = "количество байт на пиксель:" + pixelFormat[0];info_contain[2] = "формат пикселей:" + pixelFormat[1] ;
- File.WriteAllLines(info_path, info_contain, Encoding.UTF8);// создание документа по важным критериям этого файла
- }
- return colorMatrix;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement