Example #1
0
        /// <summary>
        /// 选择本地图片
        /// </summary>
        private void detailPic_Click(object sender, EventArgs e)
        {
            openFileDialog.Filter           = "JPEG|*.jpeg|JPG|*.jpg|GIF|*.gif|PNG|*.png";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;
            var detailW = this.detailPic.Size.Width;
            var detailH = this.detailPic.Size.Height;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                var path   = openFileDialog.FileName;
                var img    = Image.FromFile(path);
                var type   = Path.GetFileName(openFileDialog.FileName);
                var result = new ResoponseResult();
                this.PushImages(img, path, type, result);
                if (result.Code == "errorMax")
                {
                    MessageBox.Show(result.Message);
                    return;
                }
                this.detailPic.Image = ImageUtil.CreateThumbnailImage(img, detailW, detailH);
            }
        }
Example #2
0
        /// <summary>
        /// 加入到图片队列
        /// </summary>
        public void PushImages(Image img, string imgPath, string imgType, ResoponseResult resoponse = null)
        {
            if (resoponse != null)
            {
                resoponse.Count++;
                resoponse.Code    = "ok";
                resoponse.Message = $"上传{resoponse.Count}张图片成功!";
            }
            var detailW = this.detailPic.Size.Width;
            var detailH = this.detailPic.Size.Height;
            var width   = 150;
            var height  = 150;
            //构建Pic容器
            var x   = 20;
            var y   = 0;
            var tag = 0;
            //获取最后一个Pic
            var lastPic = this.PicList.LastOrDefault();

            if (lastPic != null)
            {
                x   = lastPic.Location.X + 170;
                y   = lastPic.Location.Y;
                tag = Convert.ToInt16(lastPic.Tag) + 1;
            }
            PictureBox pic = new PictureBox();

            pic.Location = new System.Drawing.Point(x, y);
            pic.Name     = "pic" + tag;
            pic.Tag      = tag;
            pic.Size     = new System.Drawing.Size(width, height);
            pic.TabIndex = 0;
            pic.TabStop  = false;
            pic.Cursor   = Cursors.Hand;
            pic.Click   += picPicBox_Click;
            pic.Paint   += picPicBox_Paint;
            var imgParam = new ImageParamEdit
            {
                YuanImg   = img,
                SuoImg    = ImageUtil.CreateThumbnailImage(img, width, height),
                DetailImg = ImageUtil.CreateThumbnailImage(img, detailW, detailH),
                IsUpImg   = true,
                ImagePath = imgPath,
                ImageType = imgType
            };

            pic.Image = imgParam.SuoImg;
            this.PicList.Add(pic);
            this.Images.Add(imgParam);
            //添加缩略图
            if (this.picPanel.InvokeRequired)
            {
                ThreadMethood t = () => {
                    this.picPanel.Controls.Add(pic);
                    this.SetDetailImg();
                };
                this.picPanel.Invoke(t);
            }
            else
            {
                this.picPanel.Controls.Add(pic);
                this.SetDetailImg();
            }
        }