Пример #1
0
 /// <summary>
 /// パラメータ調整用に生成したビットマップ画像を保存する
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void buttonSaveFile_Click(object sender, EventArgs e)
 {
     if (saveFileDialog.ShowDialog() == DialogResult.OK)
     {
         m7SegMatrix.save(saveFileDialog.FileName);
     }
 }
Пример #2
0
        /// <summary>
        /// 連番画像の変換を開始する
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonStartConvert_Click(object sender, EventArgs e)
        {
            if (!checkValidInputForConvert())
            {
                return;
            }

            string inputFileNameHeader  = textBoxInputFolder.Text + "\\" + textBoxInputPrefix.Text;
            string outputFileNameHeader = textBoxOutputFolder.Text + "\\" + textBoxOutputPrefix.Text;
            string output7smFileName    = textBox7smOutputFile.Text;
            int    convertCount         = (int)numericUpDownConvertCount.Value;

            string confirmMessage = createConfirmMessage(inputFileNameHeader, outputFileNameHeader, output7smFileName, convertCount);

            if (MessageBox.Show(confirmMessage, "確認", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
            {
                ProgressForm f = new ProgressForm();

                f.Owner = this;
                f.Show();

                this.Enabled = false;

                f.Title         = "連番画像変換中";
                f.ProgressCount = convertCount;

                FileStream   fs = null;
                BinaryWriter bw = null;

                if (checkBox7smOutputFile.Checked)
                {
                    fs = new FileStream(output7smFileName, FileMode.Create);
                    bw = new BinaryWriter(fs);
                }

                for (int i = 0; i < convertCount; i++)
                {
                    if (f.IsCanceled)
                    {
                        break;
                    }

                    string      inputFileName  = inputFileNameHeader + i.ToString("D4") + ".bmp";
                    string      outputFileName = outputFileNameHeader + i.ToString("D4") + ".bmp";
                    _7SegMatrix matrix         = new _7SegMatrix(inputFileName);
                    matrix.convert(trackBarThreshold.Value);

                    if (checkBoxOutputFolder.Checked)
                    {
                        matrix.save(outputFileName);
                    }

                    if (checkBox7smOutputFile.Checked)
                    {
                        byte[] _7SegPattern = matrix.get7SegPattern();
                        bw.Write(_7SegPattern);
                    }

                    f.ProgressValue = i + 1;
                    Application.DoEvents();
                }

                if (checkBox7smOutputFile.Checked)
                {
                    bw.Close();
                    fs.Close();
                }

                if (f.DialogResult == DialogResult.OK)
                {
                    MessageBox.Show("完了しました");
                }
                else
                {
                    MessageBox.Show("中断しました");
                }

                this.Activate();
                f.Close();

                this.Enabled = true;
            }
        }