Ejemplo n.º 1
0
        private void buttonOpenPic_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog1 = new OpenFileDialog();

            fileDialog1.InitialDirectory = "d://";
            fileDialog1.Filter           = "xls files (*.jpg;*.png)|*.jpg;*.png|All files (*.*)|*.*";
            fileDialog1.FilterIndex      = 1;
            fileDialog1.RestoreDirectory = true;
            if (fileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBoxSrcPic.Text = fileDialog1.FileName;

                _initImage = PicManage.GetFromFile(textBoxSrcPic.Text);
                _zoomRate.Reset();
                _zoomRate.SetRate(10);
                _zoomRate.SetSize(_initImage.Width, _initImage.Height);

                ShowPicOnCtrl(_initImage);
                SetSpliteRect(false);
                pictureBoxSrc.Invalidate();

                textBoxOutFileName.Text = Path.GetFileNameWithoutExtension(textBoxSrcPic.Text);
            }
            else
            {
            }
        }
Ejemplo n.º 2
0
        void DoSplite()
        {
            if (_initImage == null)
            {
                return;
            }

            try
            {
                Directory.CreateDirectory(textBoxSaveDir.Text);
                string fileName = GetSaveFileName();
                string fileType = comboBoxFileType.Text;

                int i = 0;
                //切割文件
                using (FileStream sFileStream = new FileStream(textBoxSrcPic.Text, FileMode.Open))
                {
                    Image initImage = Image.FromStream(sFileStream, true);

                    int   quality   = 100; //图片质量
                    Image destImage = null;
                    int   outWidth  = int.Parse(textBoxOutPicWidth.Text);

                    int widthNum = _splitRectGroup.GetWidthNum();
                    foreach (Rectangle rect in _splitRectGroup.GetRectsSplit())
                    {
                        string filePath = Path.Combine(textBoxSaveDir.Text, string.Format("{0}_{1}_{2}.{3}", textBoxOutFileName.Text, i % widthNum, i / widthNum, fileType));
                        File.Delete(filePath);

                        bool ret = PicManage.SplitPic(initImage, rect.X, rect.Y, rect.Width, rect.Height,
                                                      ref destImage, outWidth);

                        if (ret)
                        {
                            //获取系统编码类型数组,包含了jpeg,bmp,png,gif,tiff
                            ImageCodecInfo    ici = PicManage.GetCodeInfo(filePath);
                            EncoderParameters ep  = new EncoderParameters(1);
                            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
                            destImage.Save(filePath, ici, ep);
                        }

                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void buttonZoomIn_Click(object sender, EventArgs e)
        {
            if (_initImage == null)
            {
                return;
            }

            int widthNew  = 0;
            int heightNew = 0;

            _zoomRate.GetNextZoomIn(ref widthNew, ref heightNew);

            Image newImage = null;;

            PicManage.ZoomAuto(_initImage, ref newImage, widthNew, heightNew);
            if (newImage != null)
            {
                ShowPicOnCtrl(newImage);
            }
        }