コード例 #1
0
 private void btn_restore_Click(object sender, EventArgs e)
 {
     try
     {
         curBitmap = (Bitmap)Image.FromFile(curFileName);
         //实例化类
         pointbmp        = new PointBitmap(curBitmap);
         imageProcessing = new ImageProcessing(curBitmap);
     }
     catch (Exception exp)
     {
         MessageBox.Show(exp.Message);
     }
     Invalidate();
 }
コード例 #2
0
        private void btn_open_Click(object sender, EventArgs e)
        {
            //创建OpenFileDialog
            OpenFileDialog opnDlg = new OpenFileDialog();

            //为图像选择一个筛选器
            opnDlg.Filter = "所有图像文件|*.bmp;*.pcx;*.png;*.jpg;*.gif;" +
                            "*.tif;*.ico;*.dxf;*.cgm;*.cdr;*.wmf;*.eps;*.emf|" +
                            "位图(*.bmp;*.jpg;*.png;...)|*.bmp;*.pcx;*.png;*.jpg;*.gif;*.tif;*.ico|" +
                            "矢量图(*.wmf;*.eps;*.emf;...)|*.dxf;*.cgm;*.cdr;*.wmf;*.eps;*.emf";
            //设置对话框标题
            opnDlg.Title = "打开图像文件";
            //启用“帮助”按钮
            opnDlg.ShowHelp = true;

            //如果结果为“打开”,选定文件
            if (opnDlg.ShowDialog() == DialogResult.OK)
            {
                //读取当前选中的文件名
                curFileName = opnDlg.FileName;

                //使用Image.FromFile创建图像对象
                try
                {
                    //防止连续打开文件造成内存不足,每次赋值之前把上次的值清空
                    if (curBitmap != null)
                    {
                        curBitmap.Dispose();
                    }
                    curBitmap = (Bitmap)Image.FromFile(curFileName);
                    //实例化类
                    pointbmp        = new PointBitmap(curBitmap);
                    imageProcessing = new ImageProcessing(curBitmap);
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message);
                }
            }
            //对窗体进行重新绘制,这将强制执行paint事件处理程序
            Invalidate();
        }