Пример #1
0
        //zapisanie palety
        private void SavePaletteButton_Click(object sender, EventArgs e)
        {
            SaveImageWin.InitialDirectory = "./";
            SaveImageWin.Filter           = "png image|*.png|jpg image|*.jpg|bmp image|*.bmp";
            SaveImageWin.Title            = "Save an Image File";
            SaveImageWin.ShowDialog();

            if (saveType == 0 || saveType == 1) //zapisanie kolorowej grafiki
            {
                if (SaveImageWin.FileName != "")
                {
                    System.IO.FileStream fs = (System.IO.FileStream)SaveImageWin.OpenFile();
                    Properties.Settings.Default.basePath = SaveImageWin.FileName;
                    switch (SaveImageWin.FilterIndex)
                    {
                    case 1:
                        palette.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                        break;

                    case 2:
                        palette.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;

                    case 3:
                        palette.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                    }

                    //savePath = SaveImageWin.FileName;

                    fs.Close();
                }
            }
        }
Пример #2
0
        //zapiasanie pliku z wybraniem miejsca zapisu
        private void SaveAsFile()
        {
            SaveImageWin.InitialDirectory = Properties.Settings.Default.basePath;
            SaveImageWin.Filter           = "png image|*.png|jpg image|*.jpg|bmp image|*.bmp";
            SaveImageWin.Title            = "Save an Image File";
            SaveImageWin.ShowDialog();

            if (saveType == 0 || saveType == 1) //zapisanie kolorowej grafiki
            {
                if (SaveImageWin.FileName != "")
                {
                    System.IO.FileStream fs = (System.IO.FileStream)SaveImageWin.OpenFile();
                    Properties.Settings.Default.basePath = SaveImageWin.FileName;
                    switch (SaveImageWin.FilterIndex)
                    {
                    case 1:
                        sourcePicture.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                        break;

                    case 2:
                        sourcePicture.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;

                    case 3:
                        sourcePicture.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                    }
                    savePath = SaveImageWin.FileName;
                    fs.Close();
                }
            }
            if (saveType == 0 || saveType == 2) //zapisanie szarej grafiki
            {
                if (saveType == 0)
                {
                    SaveImageWin.FileName = SaveImageWin.FileName.Substring(0, SaveImageWin.FileName.Length - 4) + "_gray" +
                                            SaveImageWin.FileName.Substring(SaveImageWin.FileName.Length - 4, 4);
                }

                if (SaveImageWin.FileName != "")
                {
                    System.IO.FileStream fs = (System.IO.FileStream)SaveImageWin.OpenFile();
                    Properties.Settings.Default.basePath = SaveImageWin.FileName;
                    switch (SaveImageWin.FilterIndex)
                    {
                    case 1:
                        ImageToGray(sourcePicture, grayScaleValue).Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                        break;

                    case 2:
                        ImageToGray(sourcePicture, grayScaleValue).Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;

                    case 3:
                        ImageToGray(sourcePicture, grayScaleValue).Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                    }

                    if (saveType == 2)
                    {
                        savePath = SaveImageWin.FileName;
                    }
                    fs.Close();
                }
            }
        }