Exemple #1
0
        /********************************************************************************
        *  パラメータ調整
        ********************************************************************************/

        /// <summary>
        /// パラメータ調整用のビットマップ画像を開く
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOpenFile_Click(object sender, EventArgs e)
        {
            if (openFileDialogBmp.ShowDialog() == DialogResult.OK)
            {
                m7SegMatrix = new _7SegMatrix(openFileDialogBmp.FileName);
                drawConvertPicture(m7SegMatrix);
            }
        }
Exemple #2
0
        /// <summary>
        /// 再生スレッドのメイン処理
        /// 閉じるボタンが押下されるか、7セグマトリクスの最後まで再生したら終了する。
        /// </summary>
        private void doWork()
        {
            BinaryReader br           = new BinaryReader(mFs);
            Stopwatch    sw           = new Stopwatch();
            decimal      drawInterval = 1000m / mFps;
            decimal      nextDrawTime = 0;

            StartPlayer();
            sw.Start();

            while (mFs.Position < mFs.Length)
            {
                byte[]      _7SegPattern = br.ReadBytes(_7SegMatrix._7SEG_NUM_IN_MATRIX);
                _7SegMatrix matrix       = new _7SegMatrix(_7SegPattern);

                // 終了処理を共通化したかったので、フラグを使用して、閉じるボタンが
                // 押下された場合と押下されず再生が終了した場合で同じ経路を通るようにした。
                if (mIsCanceled)
                {
                    break;
                }

                // System.Timers.Timerの周期ハンドラは満足のいく精度でなかったため、
                // ストップウォッチで経過時間をポーリングで計測する方式とした。
                while (true)
                {
                    if (nextDrawTime <= sw.ElapsedMilliseconds)
                    {
                        pictureBoxIplScreen.BeginInvoke(new System.Action <_7SegMatrix>(delegateDraw), matrix);
                        nextDrawTime += drawInterval;
                        break;
                    }
                    else
                    {
                        // 負荷は上がるが描画タイミング精度を向上させるため最小周期でポーリングする。
                        System.Threading.Thread.Sleep(1);
                    }
                }
            }

            sw.Stop();
            StopPlayer();

            br.Close();
            mFs.Close();

            this.BeginInvoke(new System.Action(delegateClose));
        }
Exemple #3
0
 /// <summary>
 /// 入力画像⇒出力画像変換を表示する
 /// </summary>
 /// <param name="matrix">7セグマトリクスのインスタンス</param>
 private void drawConvertPicture(_7SegMatrix matrix)
 {
     matrix.drawInputPicture(pictureBoxIplInput);
     matrix.convert(trackBarThreshold.Value);
     matrix.drawOutputPicture(pictureBoxIplOutput);
 }
Exemple #4
0
 /// <summary>
 /// サンプル画像の変換を表示する
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ToolForm_Load(object sender, EventArgs e)
 {
     m7SegMatrix = new _7SegMatrix(Properties.Resources.SAMPLE);
     drawConvertPicture(m7SegMatrix);
 }
Exemple #5
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;
            }
        }
Exemple #6
0
 /// <summary>
 /// 委譲描画
 /// タイトルバーに前回からの描画間隔時間を表示する
 /// </summary>
 /// <param name="matrix"></param>
 private void delegateDraw(_7SegMatrix matrix)
 {
     matrix.drawOutputPicture(pictureBoxIplScreen);
 }