Exemplo n.º 1
0
        private void save_Click(object sender, EventArgs e)
        {
            try
            {
                // if (!isOpen)
                {
                    FileDialog a = new SaveFileDialog();
                    a.ShowDialog();
                    //изображение
                    int c = (int)Math.Sqrt(board.Length);

                    Bitmap bmp = new Bitmap(c, c);
                    Color[,] clr = new Color[c, c];

                    for (int i = 0; i < c; i++)
                    {
                        for (int j = 0; j < c; j++)
                        {
                            if (board[i, j].BackColor != defaultPixelColor)
                            {
                                bmp.SetPixel(j, i, board[i, j].BackColor);
                            }
                            clr[i, j] = board[i, j].BackColor;
                        }
                    }
                    string        name    = getName(a.FileName);
                    DirectoryInfo dirInfo = new DirectoryInfo(a.FileName);
                    if (!dirInfo.Exists)
                    {
                        dirInfo.Create();
                    }
                    else
                    {
                        dirInfo.Delete();
                        dirInfo.Create();
                    }
                    if (a.FileName != null)
                    {
                        bmp.Save(a.FileName + "\\" + name + ".png");
                    }

                    //сериализации

                    CoolImage.CoolImage saved = new CoolImage.CoolImage(clr, bmp);

                    saved.Save(a.FileName + "\\" + name + ".bin", CoolImage.CoolImage.SerializeFormat.Binary);
                    // saved.Save(a.FileName + "\\" + name + ".xml", CoolImage.CoolImage.SerializeFormat.Xml);
                    saved.Save(a.FileName + "\\" + name + ".soap", CoolImage.CoolImage.SerializeFormat.Soap);
                }
                //if file was opened from saved directory
            }
            catch { MessageBox.Show("You've done something wrong, sorry. You could try again"); }
        }
Exemplo n.º 2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();

            of.Filter = "Сериализированный объект bin (.bin)|*.bin|Сериализованный объект (.soap) |*.soap| Изображение (.png) |*.png";
            of.ShowDialog();
            string a = of.FileName;
            // try
            {//check if is in cteated by this program directory
                FileInfo binar = new FileInfo(getName(a) + ".bin");
                FileInfo soap  = new FileInfo(getName(a) + ".soap");
                FileInfo png   = new FileInfo(getName(a) + ".png");
                if (binar.Exists && soap.Exists && png.Exists)
                {
                    isOpen = true;
                }


                CoolImage.CoolImage cl = new CoolImage.CoolImage();
                cl.Read(a);
                Create_board((int)Math.Sqrt(cl.pixelArr.Length), cl.pixelArr);
            }
            //  catch { MessageBox.Show("You've done something wrong, sorry. You could try again"); }
        }