Esempio n. 1
0
        // 打开新窗口显示图片
        private bool showImage()
        {
            try
            {
                sFile = new FileStream(FILE_PATH, FileMode.Open);
                sReader = new StreamReader(sFile);
            }
            catch (System.IO.FileNotFoundException e)
            {
                MessageBox.Show("请先点击开始按钮进行数据记录", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            catch
            {
                MessageBox.Show("数据打开错误,如果正在进行记录请先点击停止按钮", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            // ImageForm窗口被释放后重新new
            if (imageForm.IsDisposed)
            {
                imageForm = new ImageForm();
            }

            // 使生成的窗口在主窗口右侧
            imageForm.Show();
            imageForm.Location = new Point(this.Location.X + this.Size.Width, this.Location.Y);

            string line;
            Point point = new Point();

            bitmap = new Bitmap(imageForm.getPanel().Width, imageForm.getPanel().Height);
            Graphics g = Graphics.FromImage(bitmap);
            g.FillRectangle(new SolidBrush(Color.White), 0, 0, imageForm.getPanel().Width, imageForm.getPanel().Height);
            while ((line = sReader.ReadLine()) != null)
            {
                string[] sArray=line.Split(' ');
                point.X = int.Parse(sArray[0]);
                point.Y = int.Parse(sArray[1]);
                bitmap.SetPixel(point.X >> 1, point.Y >> 1, Color.Red);
            }
            g = imageForm.getPanel().CreateGraphics();
            g.DrawImage(bitmap, 0, 0);
            sReader.Close();
            sFile.Close();
            return true;
        }
Esempio n. 2
0
 private void init()
 {
     imageForm = new ImageForm();
 }